ConfigurationServiceImpl implements ConfigurationManagementService { @GET @Override public Response getConfiguration(@HeaderParam("If-Modified-Since") String ifModifiedSince) { String msg; try { PlatformConfiguration config = DeviceMgtAPIUtils.getPlatformConfigurationManagementService(). getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH); ConfigurationEntry configurationEntry = new ConfigurationEntry(); configurationEntry.setContentType("text"); configurationEntry.setName("notifierFrequency"); configurationEntry.setValue(PolicyManagerUtil.getMonitoringFrequency()); List<ConfigurationEntry> configList = config.getConfiguration(); if (configList == null) { configList = new ArrayList<>(); configList.add(configurationEntry); } config.setConfiguration(configList); return Response.ok().entity(config).build(); } catch (ConfigurationManagementException | PolicyManagementException e) { msg = "Error occurred while retrieving the general platform configuration"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }  @GET @Override Response getConfiguration(@HeaderParam("If-Modified-Since") String ifModifiedSince); @PUT @Override Response updateConfiguration(PlatformConfiguration config);  }
@Test(description = "This method tests the getConfiguration method of ConfigurationManagementService under valid " + "conditions") public void testGetConfigurationWithSuccessConditions() throws ConfigurationManagementException { PowerMockito.stub(PowerMockito.method(PolicyManagerUtil.class, "getMonitoringFrequency")).toReturn(60); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getPlatformConfigurationManagementService")) .toReturn(platformConfigurationManagementService); Mockito.doReturn(platformConfiguration).when(platformConfigurationManagementService) .getConfiguration(Mockito.any()); Response response = configurationManagementService.getConfiguration("test"); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getConfiguration request " + "failed with valid parameters"); List<ConfigurationEntry> configurationEntryList = new ArrayList<>(); ConfigurationEntry configurationEntry = new ConfigurationEntry(); configurationEntry.setContentType("String"); configurationEntry.setName("test"); configurationEntry.setValue("test"); configurationEntryList.add(configurationEntry); platformConfiguration.setConfiguration(configurationEntryList); Mockito.reset(platformConfigurationManagementService); Mockito.doReturn(platformConfiguration).when(platformConfigurationManagementService) .getConfiguration(Mockito.any()); response = configurationManagementService.getConfiguration("test"); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getConfiguration request " + "failed with valid parameters"); }
@Test(description = "This method tests the getConfiguration method under negative conditions") public void testGetConfigurationUnderNegativeConditions() throws ConfigurationManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getPlatformConfigurationManagementService")) .toReturn(platformConfigurationManagementService); Mockito.reset(platformConfigurationManagementService); Mockito.doThrow(new ConfigurationManagementException()).when(platformConfigurationManagementService) .getConfiguration(Mockito.any()); Response response = configurationManagementService.getConfiguration("test"); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "getConfiguration request " + "succeeded under negative conditions"); }