List of usage examples for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE
String APPLICATION_JSON_UTF8_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE.
Click Source Link
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResourceTest.java
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Tests GET request on /rest/v1/softwaremodules/{smId}.") public void getSoftwareModule() throws Exception { final SoftwareModule os = testdataFactory.createSoftwareModuleOs(); mvc.perform(get("/rest/v1/softwaremodules/{smId}", os.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo(os.getName()))) .andExpect(jsonPath("$.version", equalTo(os.getVersion()))) .andExpect(jsonPath("$.description", equalTo(os.getDescription()))) .andExpect(jsonPath("$.vendor", equalTo(os.getVendor()))) .andExpect(jsonPath("$.type", equalTo(os.getType().getKey()))) .andExpect(jsonPath("$.deleted", equalTo(os.isDeleted()))) .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.createdAt", equalTo(os.getCreatedAt()))) .andExpect(jsonPath("$._links.metadata.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/metadata?offset=0&limit=50"))) .andExpect(jsonPath("$._links.type.href", equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId()))) .andExpect(jsonPath("$._links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))); assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResourceTest.java
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Verfies that the create request actually results in the creation of the modules in the repository.") public void createSoftwareModules() throws Exception { final SoftwareModule os = entityFactory.softwareModule().create().name("name1").type(osType) .version("version1").vendor("vendor1").description("description1").build(); final SoftwareModule ah = entityFactory.softwareModule().create().name("name3").type(appType) .version("version3").vendor("vendor3").description("description3").build(); final List<SoftwareModule> modules = Arrays.asList(os, ah); final long current = System.currentTimeMillis(); final MvcResult mvcResult = mvc .perform(post("/rest/v1/softwaremodules/").accept(MediaType.APPLICATION_JSON_UTF8_VALUE) .content(JsonBuilder.softwareModules(modules)).contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("name1"))) .andExpect(jsonPath("[0].version", equalTo("version1"))) .andExpect(jsonPath("[0].description", equalTo("description1"))) .andExpect(jsonPath("[0].vendor", equalTo("vendor1"))) .andExpect(jsonPath("[0].type", equalTo("os"))) .andExpect(jsonPath("[0].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[1].name", equalTo("name3"))) .andExpect(jsonPath("[1].version", equalTo("version3"))) .andExpect(jsonPath("[1].description", equalTo("description3"))) .andExpect(jsonPath("[1].vendor", equalTo("vendor3"))) .andExpect(jsonPath("[1].type", equalTo("application"))) .andExpect(jsonPath("[1].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[1].createdAt", not(equalTo(0)))).andReturn(); final SoftwareModule osCreated = softwareModuleManagement .getByNameAndVersionAndType("name1", "version1", osType.getId()).get(); final SoftwareModule appCreated = softwareModuleManagement .getByNameAndVersionAndType("name3", "version3", appType.getId()).get(); assertThat(JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).as("Response contains invalid self href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + osCreated.getId()); assertThat(JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).as("Response contains links self href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId()); assertThat(softwareModuleManagement.findAll(PAGE)).as("Wrong softwaremodule size").hasSize(2); assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(os.getName()); assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getCreatedBy()) .as("Softwaremoudle created by is wrong").isEqualTo("uploadTester"); assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getCreatedAt()) .as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current); assertThat(softwareModuleManagement.findByType(PAGE, appType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(ah.getName()); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResourceTest.java
@Test @Description("Verfies the successful creation of metadata and the enforcement of the meta data quota.") public void createMetadata() throws Exception { final String knownKey1 = "knownKey1"; final String knownValue1 = "knownValue1"; final String knownKey2 = "knownKey2"; final String knownValue2 = "knownValue1"; final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); final JSONArray metaData1 = new JSONArray(); metaData1.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); metaData1.put(new JSONObject().put("key", knownKey2).put("value", knownValue2).put("targetVisible", true)); mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).content(metaData1.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0]key", equalTo(knownKey1))) .andExpect(jsonPath("[0]value", equalTo(knownValue1))) .andExpect(jsonPath("[0]targetVisible", equalTo(false))) .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))) .andExpect(jsonPath("[1]targetVisible", equalTo(true))); final SoftwareModuleMetadata metaKey1 = softwareModuleManagement .getMetaDataBySoftwareModuleId(sm.getId(), knownKey1).get(); final SoftwareModuleMetadata metaKey2 = softwareModuleManagement .getMetaDataBySoftwareModuleId(sm.getId(), knownKey2).get(); assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); // verify quota enforcement final int maxMetaData = quotaManagement.getMaxMetaDataEntriesPerSoftwareModule(); final JSONArray metaData2 = new JSONArray(); for (int i = 0; i < maxMetaData - metaData1.length() + 1; ++i) { metaData2.put(new JSONObject().put("key", knownKey1 + i).put("value", knownValue1 + i)); }//from w w w.j a va 2 s. c o m mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).content(metaData2.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden()); // verify that the number of meta data entries has not changed // (we cannot use the PAGE constant here as it tries to sort by ID) assertThat(softwareModuleManagement .findMetaDataBySoftwareModuleId(PageRequest.of(0, Integer.MAX_VALUE), sm.getId()) .getTotalElements()).isEqualTo(metaData1.length()); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResourceTest.java
@Test @Description("Verfies the successfull update of metadata based on given key.") public void updateMetadata() throws Exception { // prepare and create metadata for update final String knownKey = "knownKey"; final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue) .put("targetVisible", true); mvc.perform(put("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey) .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON) .content(jsonObject.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); final SoftwareModuleMetadata assertDS = softwareModuleManagement .getMetaDataBySoftwareModuleId(sm.getId(), knownKey).get(); assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); assertThat(assertDS.isTargetVisible()).as("target visible is wrong").isTrue(); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeResourceTest.java
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests.") public void getSoftwareModuleTypes() throws Exception { final SoftwareModuleType testType = createTestType(); mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.key=='" + osType.getKey() + "')].name", contains(osType.getName()))) .andExpect(jsonPath("$.content.[?(@.key=='" + osType.getKey() + "')].description", contains(osType.getDescription()))) .andExpect(jsonPath("$.content.[?(@.key=='" + osType.getKey() + "')].maxAssignments", contains(1))) .andExpect(jsonPath("$.content.[?(@.key=='" + osType.getKey() + "')].key", contains("os"))) .andExpect(jsonPath("$.content.[?(@.key=='" + runtimeType.getKey() + "')].name", contains(runtimeType.getName()))) .andExpect(jsonPath("$.content.[?(@.key=='" + runtimeType.getKey() + "')].description", contains(runtimeType.getDescription()))) .andExpect(jsonPath("$.content.[?(@.key=='" + runtimeType.getKey() + "')].maxAssignments", contains(1)))//from w w w . j ava 2 s. co m .andExpect( jsonPath("$.content.[?(@.key=='" + runtimeType.getKey() + "')].key", contains("runtime"))) .andExpect(jsonPath("$.content.[?(@.key=='" + appType.getKey() + "')].name", contains(appType.getName()))) .andExpect(jsonPath("$.content.[?(@.key=='" + appType.getKey() + "')].description", contains(appType.getDescription()))) .andExpect(jsonPath("$.content.[?(@.key=='" + appType.getKey() + "')].maxAssignments", contains(Integer.MAX_VALUE))) .andExpect( jsonPath("$.content.[?(@.key=='" + appType.getKey() + "')].key", contains("application"))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].id", contains(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].name", contains("TestName123"))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].description", contains("Desc1234"))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].createdBy", contains("uploadTester"))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].createdAt", contains(testType.getCreatedAt()))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].lastModifiedBy", contains("uploadTester"))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].lastModifiedAt", contains(testType.getLastModifiedAt()))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].maxAssignments", contains(5))) .andExpect(jsonPath("$.content.[?(@.key=='test123')].key", contains("test123"))) .andExpect(jsonPath("$.total", equalTo(4))); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeResourceTest.java
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.") public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception { final SoftwareModuleType testType = createTestType(); // descending mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[1].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[1].name", equalTo("TestName123"))) .andExpect(jsonPath("$.content.[1].description", equalTo("Desc1234"))) .andExpect(jsonPath("$.content.[1].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.content.[1].createdAt", equalTo(testType.getCreatedAt()))) .andExpect(jsonPath("$.content.[1].lastModifiedBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.content.[1].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) .andExpect(jsonPath("$.content.[1].maxAssignments", equalTo(5))) .andExpect(jsonPath("$.content.[1].key", equalTo("test123"))) .andExpect(jsonPath("$.total", equalTo(4))); // ascending/*from ww w.ja v a 2 s. co m*/ mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[2].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[2].name", equalTo("TestName123"))) .andExpect(jsonPath("$.content.[2].description", equalTo("Desc1234"))) .andExpect(jsonPath("$.content.[2].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.content.[2].createdAt", equalTo(testType.getCreatedAt()))) .andExpect(jsonPath("$.content.[2].lastModifiedBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.content.[2].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) .andExpect(jsonPath("$.content.[2].maxAssignments", equalTo(5))) .andExpect(jsonPath("$.content.[2].key", equalTo("test123"))) .andExpect(jsonPath("$.total", equalTo(4))); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeResourceTest.java
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests.") public void createSoftwareModuleTypes() throws Exception { final List<SoftwareModuleType> types = Arrays.asList( entityFactory.softwareModuleType().create().key("test1").name("TestName1").description("Desc1") .colour("col1").maxAssignments(1).build(), entityFactory.softwareModuleType().create().key("test2").name("TestName2").description("Desc2") .colour("col2").maxAssignments(2).build(), entityFactory.softwareModuleType().create().key("test3").name("TestName3").description("Desc3") .colour("col3").maxAssignments(3).build()); final MvcResult mvcResult = mvc .perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("TestName1"))) .andExpect(jsonPath("[0].key", equalTo("test1"))) .andExpect(jsonPath("[0].description", equalTo("Desc1"))) .andExpect(jsonPath("[0].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[0].maxAssignments", equalTo(1))) .andExpect(jsonPath("[1].name", equalTo("TestName2"))) .andExpect(jsonPath("[1].key", equalTo("test2"))) .andExpect(jsonPath("[1].description", equalTo("Desc2"))) .andExpect(jsonPath("[1].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[1].maxAssignments", equalTo(2))) .andExpect(jsonPath("[2].name", equalTo("TestName3"))) .andExpect(jsonPath("[2].key", equalTo("test3"))) .andExpect(jsonPath("[2].description", equalTo("Desc3"))) .andExpect(jsonPath("[2].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[2].createdAt", not(equalTo(0)))) .andExpect(jsonPath("[2].maxAssignments", equalTo(3))).andReturn(); final SoftwareModuleType created1 = softwareModuleTypeManagement.getByKey("test1").get(); final SoftwareModuleType created2 = softwareModuleTypeManagement.getByKey("test2").get(); final SoftwareModuleType created3 = softwareModuleTypeManagement.getByKey("test3").get(); assertThat(JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created1.getId()); assertThat(JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created2.getId()); assertThat(JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created3.getId()); assertThat(softwareModuleTypeManagement.count()).isEqualTo(6); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeResourceTest.java
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} GET requests.") public void getSoftwareModuleType() throws Exception { final SoftwareModuleType testType = createTestType(); mvc.perform(/*from w w w . j a v a2 s . co m*/ get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo("TestName123"))) .andExpect(jsonPath("$.description", equalTo("Desc1234"))) .andExpect(jsonPath("$.maxAssignments", equalTo(5))) .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt()))) .andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester"))) .andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt()))) .andExpect(jsonPath("$.deleted", equalTo(testType.isDeleted()))); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetResourceTest.java
@Test @Description("Ensures that a post request for creating multiple targets works.") public void createTargetsListReturnsSuccessful() throws Exception { final Target test1 = entityFactory.target().create().controllerId("id1").name("testname1") .securityToken("token").address("amqp://test123/foobar").description("testid1").build(); final Target test2 = entityFactory.target().create().controllerId("id2").name("testname2") .description("testid2").build(); final Target test3 = entityFactory.target().create().controllerId("id3").name("testname3") .description("testid3").build(); final List<Target> targets = Arrays.asList(test1, test2, test3); final MvcResult mvcResult = mvc .perform(post("/rest/v1/targets/").content(JsonBuilder.targets(targets, true)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("testname1"))) .andExpect(jsonPath("[0].controllerId", equalTo("id1"))) .andExpect(jsonPath("[0].description", equalTo("testid1"))) .andExpect(jsonPath("[0].createdAt", not(equalTo(0)))) .andExpect(jsonPath("[0].createdBy", equalTo("bumlux"))) .andExpect(jsonPath("[0].securityToken", equalTo("token"))) .andExpect(jsonPath("[0].address", equalTo("amqp://test123/foobar"))) .andExpect(jsonPath("[1].name", equalTo("testname2"))) .andExpect(jsonPath("[1].createdBy", equalTo("bumlux"))) .andExpect(jsonPath("[1].controllerId", equalTo("id2"))) .andExpect(jsonPath("[1].description", equalTo("testid2"))) .andExpect(jsonPath("[1].createdAt", not(equalTo(0)))) .andExpect(jsonPath("[1].createdBy", equalTo("bumlux"))) .andExpect(jsonPath("[2].name", equalTo("testname3"))) .andExpect(jsonPath("[2].controllerId", equalTo("id3"))) .andExpect(jsonPath("[2].description", equalTo("testid3"))) .andExpect(jsonPath("[2].createdAt", not(equalTo(0)))) .andExpect(jsonPath("[2].createdBy", equalTo("bumlux"))).andReturn(); assertThat(JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo("http://localhost/rest/v1/targets/id1"); assertThat(JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo("http://localhost/rest/v1/targets/id2"); assertThat(JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo("http://localhost/rest/v1/targets/id3"); assertThat(targetManagement.getByControllerID("id1")).isNotNull(); assertThat(targetManagement.getByControllerID("id1").get().getName()).isEqualTo("testname1"); assertThat(targetManagement.getByControllerID("id1").get().getDescription()).isEqualTo("testid1"); assertThat(targetManagement.getByControllerID("id1").get().getSecurityToken()).isEqualTo("token"); assertThat(targetManagement.getByControllerID("id1").get().getAddress().toString()) .isEqualTo("amqp://test123/foobar"); assertThat(targetManagement.getByControllerID("id2")).isNotNull(); assertThat(targetManagement.getByControllerID("id2").get().getName()).isEqualTo("testname2"); assertThat(targetManagement.getByControllerID("id2").get().getDescription()).isEqualTo("testid2"); assertThat(targetManagement.getByControllerID("id3")).isNotNull(); assertThat(targetManagement.getByControllerID("id3").get().getName()).isEqualTo("testname3"); assertThat(targetManagement.getByControllerID("id3").get().getDescription()).isEqualTo("testid3"); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetResourceTest.java
@Test @Description("Ensures that the metadata creation through API is reflected by the repository.") public void createMetadata() throws Exception { final String knownControllerId = "targetIdWithMetadata"; testdataFactory.createTarget(knownControllerId); final String knownKey1 = "knownKey1"; final String knownKey2 = "knownKey2"; final String knownValue1 = "knownValue1"; final String knownValue2 = "knownValue2"; final JSONArray metaData1 = new JSONArray(); metaData1.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); metaData1.put(new JSONObject().put("key", knownKey2).put("value", knownValue2)); mvc.perform(/*from www. j a v a 2s. c o m*/ post("/rest/v1/targets/{targetId}/metadata", knownControllerId).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).content(metaData1.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0]key", equalTo(knownKey1))) .andExpect(jsonPath("[0]value", equalTo(knownValue1))) .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); final TargetMetadata metaKey1 = targetManagement.getMetaDataByControllerId(knownControllerId, knownKey1) .get(); final TargetMetadata metaKey2 = targetManagement.getMetaDataByControllerId(knownControllerId, knownKey2) .get(); assertThat(metaKey1.getValue()).isEqualTo(knownValue1); assertThat(metaKey2.getValue()).isEqualTo(knownValue2); // verify quota enforcement final int maxMetaData = quotaManagement.getMaxMetaDataEntriesPerTarget(); final JSONArray metaData2 = new JSONArray(); for (int i = 0; i < maxMetaData - metaData1.length() + 1; ++i) { metaData2.put(new JSONObject().put("key", knownKey1 + i).put("value", knownValue1 + i)); } mvc.perform( post("/rest/v1/targets/{targetId}/metadata", knownControllerId).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).content(metaData2.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden()); // verify that the number of meta data entries has not changed // (we cannot use the PAGE constant here as it tries to sort by ID) assertThat( targetManagement.findMetaDataByControllerId(PageRequest.of(0, Integer.MAX_VALUE), knownControllerId) .getTotalElements()).isEqualTo(metaData1.length()); }