Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jian Li | 8ae9120 | 2016-03-24 14:36:16 -0700 | [diff] [blame] | 16 | package org.onosproject.rest.resources; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 17 | |
| 18 | |
Jian Li | 80cfe45 | 2016-01-14 16:04:58 -0800 | [diff] [blame] | 19 | import com.eclipsesource.json.Json; |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 20 | import com.eclipsesource.json.JsonArray; |
| 21 | import com.eclipsesource.json.JsonObject; |
| 22 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 23 | import org.hamcrest.Description; |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 24 | import org.hamcrest.Matchers; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 25 | import org.hamcrest.TypeSafeMatcher; |
| 26 | import org.junit.After; |
| 27 | import org.junit.Before; |
| 28 | import org.junit.Test; |
| 29 | import org.onlab.osgi.ServiceDirectory; |
| 30 | import org.onlab.osgi.TestServiceDirectory; |
| 31 | import org.onlab.packet.IpAddress; |
| 32 | import org.onlab.packet.MacAddress; |
| 33 | import org.onlab.rest.BaseResource; |
| 34 | import org.onosproject.codec.CodecService; |
| 35 | import org.onosproject.codec.impl.CodecManager; |
| 36 | import org.onosproject.net.DefaultHost; |
| 37 | import org.onosproject.net.DeviceId; |
| 38 | import org.onosproject.net.Host; |
| 39 | import org.onosproject.net.HostId; |
| 40 | import org.onosproject.net.HostLocation; |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 41 | import org.onosproject.net.host.HostProviderRegistry; |
| 42 | import org.onosproject.net.host.HostProviderService; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 43 | import org.onosproject.net.host.HostService; |
| 44 | import org.onosproject.net.provider.ProviderId; |
| 45 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 46 | import javax.ws.rs.NotFoundException; |
| 47 | import javax.ws.rs.client.Entity; |
| 48 | import javax.ws.rs.client.WebTarget; |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 49 | import javax.ws.rs.core.MediaType; |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 50 | import javax.ws.rs.core.Response; |
| 51 | import java.io.InputStream; |
| 52 | import java.net.HttpURLConnection; |
| 53 | import java.util.HashSet; |
| 54 | import java.util.Set; |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 55 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 56 | import static org.easymock.EasyMock.anyBoolean; |
| 57 | import static org.easymock.EasyMock.anyObject; |
| 58 | import static org.easymock.EasyMock.createMock; |
| 59 | import static org.easymock.EasyMock.expect; |
| 60 | import static org.easymock.EasyMock.expectLastCall; |
| 61 | import static org.easymock.EasyMock.replay; |
| 62 | import static org.easymock.EasyMock.verify; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 63 | import static org.hamcrest.Matchers.containsString; |
| 64 | import static org.hamcrest.Matchers.hasSize; |
| 65 | import static org.hamcrest.Matchers.is; |
| 66 | import static org.hamcrest.Matchers.notNullValue; |
| 67 | import static org.junit.Assert.assertThat; |
Ray Milkey | 02f446b | 2014-12-11 20:19:43 -0800 | [diff] [blame] | 68 | import static org.junit.Assert.fail; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 69 | import static org.onlab.packet.MacAddress.valueOf; |
| 70 | import static org.onlab.packet.VlanId.vlanId; |
| 71 | import static org.onosproject.net.PortNumber.portNumber; |
| 72 | |
| 73 | /** |
| 74 | * Simple example on how to write a JAX-RS unit test using Jersey test framework. |
| 75 | * A base class should/will be created to provide further assistance for testing. |
| 76 | */ |
Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 77 | public class HostResourceTest extends ResourceTest { |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 78 | final HostService mockHostService = createMock(HostService.class); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 79 | final HostProviderRegistry mockHostProviderRegistry = createMock(HostProviderRegistry.class); |
| 80 | final HostProviderService mockHostProviderService = createMock(HostProviderService.class); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 81 | final HashSet<Host> hosts = new HashSet<>(); |
| 82 | |
Ray Milkey | ed0b166 | 2015-02-05 09:34:29 -0800 | [diff] [blame] | 83 | /** |
| 84 | * Initializes test mocks and environment. |
| 85 | */ |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 86 | @Before |
Ray Milkey | ed0b166 | 2015-02-05 09:34:29 -0800 | [diff] [blame] | 87 | public void setUpTest() { |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 88 | expect(mockHostService.getHosts()).andReturn(hosts).anyTimes(); |
| 89 | |
| 90 | // Register the services needed for the test |
| 91 | final CodecManager codecService = new CodecManager(); |
| 92 | codecService.activate(); |
| 93 | ServiceDirectory testDirectory = |
| 94 | new TestServiceDirectory() |
| 95 | .add(HostService.class, mockHostService) |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 96 | .add(CodecService.class, codecService) |
| 97 | .add(HostProviderRegistry.class, mockHostProviderRegistry); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 98 | BaseResource.setServiceDirectory(testDirectory); |
| 99 | } |
| 100 | |
Ray Milkey | ed0b166 | 2015-02-05 09:34:29 -0800 | [diff] [blame] | 101 | /** |
| 102 | * Verifies mocks. |
| 103 | */ |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 104 | @After |
Ray Milkey | ed0b166 | 2015-02-05 09:34:29 -0800 | [diff] [blame] | 105 | public void tearDownTest() { |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 106 | verify(mockHostService); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Hamcrest matcher to check that a host representation in JSON matches |
| 111 | * the actual host. |
| 112 | */ |
| 113 | public static class HostJsonMatcher extends TypeSafeMatcher<JsonObject> { |
| 114 | private final Host host; |
| 115 | private String reason = ""; |
| 116 | |
| 117 | public HostJsonMatcher(Host hostValue) { |
| 118 | host = hostValue; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public boolean matchesSafely(JsonObject jsonHost) { |
| 123 | // Check id |
| 124 | final String jsonId = jsonHost.get("id").asString(); |
| 125 | if (!jsonId.equals(host.id().toString())) { |
| 126 | reason = "id " + host.id().toString(); |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | // Check vlan id |
| 131 | final String jsonVlanId = jsonHost.get("vlan").asString(); |
| 132 | if (!jsonVlanId.equals(host.vlan().toString())) { |
| 133 | reason = "vlan id " + host.vlan().toString(); |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | // Check mac address |
| 138 | final String jsonMacAddress = jsonHost.get("mac").asString(); |
| 139 | if (!jsonMacAddress.equals(host.mac().toString())) { |
| 140 | reason = "mac address " + host.mac().toString(); |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | // Check location element id |
| 145 | final JsonObject jsonLocation = jsonHost.get("location").asObject(); |
| 146 | final String jsonLocationElementId = jsonLocation.get("elementId").asString(); |
| 147 | if (!jsonLocationElementId.equals(host.location().elementId().toString())) { |
| 148 | reason = "location element id " + host.location().elementId().toString(); |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | // Check location port number |
| 153 | final String jsonLocationPortNumber = jsonLocation.get("port").asString(); |
| 154 | if (!jsonLocationPortNumber.equals(host.location().port().toString())) { |
| 155 | reason = "location portNumber " + host.location().port().toString(); |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | // Check Ip Addresses |
| 160 | final JsonArray jsonHostIps = jsonHost.get("ipAddresses").asArray(); |
| 161 | final Set<IpAddress> expectedHostIps = host.ipAddresses(); |
| 162 | if (jsonHostIps.size() != expectedHostIps.size()) { |
| 163 | reason = "IP address arrays differ in size"; |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void describeTo(Description description) { |
| 172 | description.appendText(reason); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Factory to allocate a host array matcher. |
| 178 | * |
| 179 | * @param host host object we are looking for |
| 180 | * @return matcher |
| 181 | */ |
| 182 | private static HostJsonMatcher matchesHost(Host host) { |
| 183 | return new HostJsonMatcher(host); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Hamcrest matcher to check that a host is represented properly in a JSON |
| 188 | * array of hosts. |
| 189 | */ |
| 190 | public static class HostJsonArrayMatcher extends TypeSafeMatcher<JsonArray> { |
| 191 | private final Host host; |
| 192 | private String reason = ""; |
| 193 | |
| 194 | public HostJsonArrayMatcher(Host hostValue) { |
| 195 | host = hostValue; |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public boolean matchesSafely(JsonArray json) { |
| 200 | boolean hostFound = false; |
sdn | 5e93545 | 2016-08-30 04:12:54 -0700 | [diff] [blame] | 201 | final int expectedAttributes = 6; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 202 | for (int jsonHostIndex = 0; jsonHostIndex < json.size(); |
| 203 | jsonHostIndex++) { |
| 204 | |
| 205 | final JsonObject jsonHost = json.get(jsonHostIndex).asObject(); |
| 206 | |
| 207 | if (jsonHost.names().size() != expectedAttributes) { |
| 208 | reason = "Found a host with the wrong number of attributes"; |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | final String jsonHostId = jsonHost.get("id").asString(); |
| 213 | if (jsonHostId.equals(host.id().toString())) { |
| 214 | hostFound = true; |
| 215 | |
| 216 | // We found the correct host, check attribute values |
| 217 | assertThat(jsonHost, matchesHost(host)); |
| 218 | } |
| 219 | } |
| 220 | if (!hostFound) { |
| 221 | reason = "Host with id " + host.id().toString() + " not found"; |
| 222 | return false; |
| 223 | } else { |
| 224 | return true; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void describeTo(Description description) { |
| 230 | description.appendText(reason); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Factory to allocate a host array matcher. |
| 236 | * |
| 237 | * @param host host object we are looking for |
| 238 | * @return matcher |
| 239 | */ |
| 240 | private static HostJsonArrayMatcher hasHost(Host host) { |
| 241 | return new HostJsonArrayMatcher(host); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Tests the result of the rest api GET when there are no hosts. |
| 246 | */ |
| 247 | @Test |
| 248 | public void testHostsEmptyArray() { |
| 249 | replay(mockHostService); |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 250 | WebTarget wt = target(); |
| 251 | String response = wt.path("hosts").request().get(String.class); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 252 | assertThat(response, is("{\"hosts\":[]}")); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Tests the result of the rest api GET when hosts are defined. |
| 257 | */ |
| 258 | @Test |
| 259 | public void testHostsArray() { |
| 260 | replay(mockHostService); |
| 261 | final ProviderId pid = new ProviderId("of", "foo"); |
| 262 | final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); |
| 263 | final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::")); |
| 264 | final Host host1 = |
| 265 | new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), |
| 266 | new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), |
| 267 | ips1); |
| 268 | final MacAddress mac2 = MacAddress.valueOf("00:00:11:00:00:02"); |
| 269 | final Set<IpAddress> ips2 = ImmutableSet.of( |
| 270 | IpAddress.valueOf("2222:2222:2222:1::"), |
| 271 | IpAddress.valueOf("2222:2222:2222:2::")); |
| 272 | final Host host2 = |
| 273 | new DefaultHost(pid, HostId.hostId(mac2), valueOf(2), vlanId((short) 2), |
| 274 | new HostLocation(DeviceId.deviceId("2"), portNumber(22), 2), |
| 275 | ips2); |
| 276 | hosts.add(host1); |
| 277 | hosts.add(host2); |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 278 | WebTarget wt = target(); |
| 279 | String response = wt.path("hosts").request().get(String.class); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 280 | assertThat(response, containsString("{\"hosts\":[")); |
| 281 | |
Jian Li | 80cfe45 | 2016-01-14 16:04:58 -0800 | [diff] [blame] | 282 | final JsonObject result = Json.parse(response).asObject(); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 283 | assertThat(result, notNullValue()); |
| 284 | |
| 285 | assertThat(result.names(), hasSize(1)); |
| 286 | assertThat(result.names().get(0), is("hosts")); |
| 287 | |
| 288 | final JsonArray hosts = result.get("hosts").asArray(); |
| 289 | assertThat(hosts, notNullValue()); |
| 290 | |
| 291 | assertThat(hosts, hasHost(host1)); |
| 292 | assertThat(hosts, hasHost(host2)); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Tests fetch of one host by Id. |
| 297 | */ |
| 298 | @Test |
| 299 | public void testSingleHostByIdFetch() { |
| 300 | final ProviderId pid = new ProviderId("of", "foo"); |
| 301 | final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); |
| 302 | final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::")); |
| 303 | final Host host1 = |
| 304 | new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), |
| 305 | new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), |
| 306 | ips1); |
| 307 | |
| 308 | hosts.add(host1); |
| 309 | |
| 310 | expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))) |
| 311 | .andReturn(host1) |
| 312 | .anyTimes(); |
| 313 | replay(mockHostService); |
| 314 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 315 | WebTarget wt = target(); |
| 316 | String response = wt.path("hosts/00:00:11:00:00:01%2F1").request().get(String.class); |
Jian Li | 80cfe45 | 2016-01-14 16:04:58 -0800 | [diff] [blame] | 317 | final JsonObject result = Json.parse(response).asObject(); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 318 | assertThat(result, matchesHost(host1)); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Tests fetch of one host by mac and vlan. |
| 323 | */ |
| 324 | @Test |
| 325 | public void testSingleHostByMacAndVlanFetch() { |
| 326 | final ProviderId pid = new ProviderId("of", "foo"); |
| 327 | final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); |
| 328 | final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::")); |
| 329 | final Host host1 = |
| 330 | new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), |
| 331 | new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), |
| 332 | ips1); |
| 333 | |
| 334 | hosts.add(host1); |
| 335 | |
| 336 | expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))) |
| 337 | .andReturn(host1) |
| 338 | .anyTimes(); |
| 339 | replay(mockHostService); |
| 340 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 341 | WebTarget wt = target(); |
| 342 | String response = wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class); |
Jian Li | 80cfe45 | 2016-01-14 16:04:58 -0800 | [diff] [blame] | 343 | final JsonObject result = Json.parse(response).asObject(); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 344 | assertThat(result, matchesHost(host1)); |
| 345 | } |
| 346 | |
Ray Milkey | 02f446b | 2014-12-11 20:19:43 -0800 | [diff] [blame] | 347 | /** |
| 348 | * Tests that a fetch of a non-existent object throws an exception. |
| 349 | */ |
| 350 | @Test |
| 351 | public void testBadGet() { |
| 352 | |
| 353 | expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))) |
| 354 | .andReturn(null) |
| 355 | .anyTimes(); |
| 356 | replay(mockHostService); |
| 357 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 358 | WebTarget wt = target(); |
Ray Milkey | 02f446b | 2014-12-11 20:19:43 -0800 | [diff] [blame] | 359 | try { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 360 | wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class); |
Ray Milkey | 02f446b | 2014-12-11 20:19:43 -0800 | [diff] [blame] | 361 | fail("Fetch of non-existent host did not throw an exception"); |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 362 | } catch (NotFoundException ex) { |
Ray Milkey | 02f446b | 2014-12-11 20:19:43 -0800 | [diff] [blame] | 363 | assertThat(ex.getMessage(), |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 364 | containsString("HTTP 404 Not Found")); |
Ray Milkey | 02f446b | 2014-12-11 20:19:43 -0800 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 368 | /** |
| 369 | * Tests post of a single host via JSON stream. |
| 370 | */ |
| 371 | @Test |
| 372 | public void testPost() { |
Ray Milkey | dc08344 | 2016-02-22 11:27:57 -0800 | [diff] [blame] | 373 | mockHostProviderService.hostDetected(anyObject(), anyObject(), anyBoolean()); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 374 | expectLastCall(); |
| 375 | replay(mockHostProviderService); |
| 376 | |
| 377 | expect(mockHostProviderRegistry.register(anyObject())).andReturn(mockHostProviderService); |
| 378 | mockHostProviderRegistry.unregister(anyObject()); |
| 379 | expectLastCall(); |
| 380 | replay(mockHostProviderRegistry); |
| 381 | |
| 382 | replay(mockHostService); |
| 383 | |
Phaneendra Manda | 2be2f88 | 2015-11-11 15:23:40 +0530 | [diff] [blame] | 384 | InputStream jsonStream = HostResourceTest.class |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 385 | .getResourceAsStream("post-host.json"); |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 386 | WebTarget wt = target(); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 387 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 388 | Response response = wt.path("hosts") |
| 389 | .request(MediaType.APPLICATION_JSON_TYPE) |
| 390 | .post(Entity.json(jsonStream)); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 391 | assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED)); |
| 392 | String location = response.getLocation().getPath(); |
Luca Prete | 283a962 | 2016-03-29 16:12:20 -0700 | [diff] [blame] | 393 | assertThat(location, Matchers.startsWith("/hosts/11:22:33:44:55:66/None")); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 394 | } |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 395 | } |
| 396 | |