protected Long getOsModule(final DistributionSet ds) { return ds.findFirstModuleByType(osType).get().getId(); }
protected Long getOsModule(final DistributionSet ds) { return ds.findFirstModuleByType(osType).get().getId(); }
@Test @Description("Create a list of meta data entries" + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void postMetadata() throws Exception { final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); final String knownKey1 = "knownKey1"; final String knownKey2 = "knownKey2"; final String knownValue1 = "knownValue1"; final String knownValue2 = "knownValue2"; final JSONArray jsonArray = new JSONArray(); jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2).put("targetVisible", true)); mockMvc.perform(post(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata", module.getId()).contentType(MediaTypes.HAL_JSON_UTF8).content(jsonArray.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8)) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)), requestFields(requestFieldWithPath("[]key").description(MgmtApiModelProperties.META_DATA_KEY), requestFieldWithPath("[]value").description(MgmtApiModelProperties.META_DATA_VALUE), requestFieldWithPath("[]targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE).optional()), responseFields(fieldWithPath("[]key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("[]value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("[]targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE) ) )); }
@Test @Description(" Update a single meta data value for speficic key." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void putMetadata() throws Exception { // prepare and create metadata for update final String knownKey = "knownKey"; final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue) .put("targetVisible", true); mockMvc.perform( put(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}", module.getId(), knownKey).contentType(MediaTypes.HAL_JSON_UTF8).content(jsonObject.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters(parameterWithName("softwareModuleId") .description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("metadataKey").description(MgmtApiModelProperties.META_DATA_KEY)), requestFields(requestFieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), requestFieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE), requestFieldWithPath("targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)))); }
@Test @Description("Delete a software module assignment." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void deleteAssignSoftwareModules() throws Exception { final DistributionSet set = testdataFactory.createUpdatedDistributionSet(); mockMvc.perform(delete( MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/assignedSM/{softwareModuleId}", set.getId(), set.findFirstModuleByType(osType).get().getId()) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)))); ; }
@Test @Description(" Delete a single meta data." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void deleteMetadata() throws Exception { // prepare and create metadata for deletion final String knownKey = "knownKey"; final String knownValue = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue)); mockMvc.perform(delete( MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{{metadataKey}", module.getId(), knownKey)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("{metadataKey").description(MgmtApiModelProperties.META_DATA_KEY)))); }
@Test @Description(" Get a single meta data value for a meta data key." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadataValue() throws Exception { // prepare and create metadata final String knownKey = "knownKey"; final String knownValue = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue)); mockMvc.perform( get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}", module.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("metadataKey").description(MgmtApiModelProperties.META_DATA_KEY)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)))); }
@Test @Description(" Get a paged list of meta data for a software module with defined page size and sorting by name descending and key starting with 'known'." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadataWithParameters() throws Exception { final int totalMetadata = 4; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); for (int index = 0; index < totalMetadata; index++) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(knownKeyPrefix + index).value(knownValuePrefix + index)); } mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata", module.getId()).param("offset", "1").param("limit", "2").param("sort", "key:DESC").param("q", "key==known*")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8)) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)), requestParameters( parameterWithName("limit").attributes(key("type").value("query")) .description(ApiModelPropertiesGeneric.LIMIT), parameterWithName("sort").description(ApiModelPropertiesGeneric.SORT), parameterWithName("offset").description(ApiModelPropertiesGeneric.OFFSET), parameterWithName("q").description(ApiModelPropertiesGeneric.FIQL)))); }
@Test @Description(" Get a paged list of meta data for a software module." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadata() throws Exception { final int totalMetadata = 4; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); for (int index = 0; index < totalMetadata; index++) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(knownKeyPrefix + index).value(knownValuePrefix + index)); } mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata", module.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8)) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS), fieldWithPath("size").type(JsonFieldType.NUMBER) .description(ApiModelPropertiesGeneric.SIZE), fieldWithPath("content").description(MgmtApiModelProperties.META_DATA), fieldWithPath("content[].key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("content[].value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("content[].targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)))); }