From eb0565b72b78a6be169f5f3b894c2ff9ea61f8e8 Mon Sep 17 00:00:00 2001 From: suthagar23 Date: Tue, 25 Jul 2017 00:41:41 +0530 Subject: [PATCH] SystemInformation REST updates --- .../SystemInformationResource1_8.java | 12 +--- .../SystemInformationResource1_8Test.java | 68 ++++++++++++++++--- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8.java index a4711f745..4103bb0eb 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8.java @@ -26,15 +26,9 @@ public class SystemInformationResource1_8 implements Listable { @Override public SimpleObject getAll(RequestContext context) throws ResponseException { SimpleObject rest = new SimpleObject(); - try { - rest.put("SystemInfo", Context.getAdministrationService().getSystemInformation()); - } - catch (Exception ex) { - System.out.println(ex.getMessage()); - } - finally { - return rest; - } + rest.put("SystemInfo", Context.getAdministrationService().getSystemInformation()); + return rest; + } @Override diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8Test.java index 45a1ab7b3..b20917aa5 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8Test.java @@ -9,33 +9,79 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import static org.junit.Assert.assertEquals; -import javax.servlet.http.HttpServletResponse; -import org.apache.struts.mock.MockHttpServletRequest; + import org.apache.struts.mock.MockHttpServletResponse; -import org.apache.commons.beanutils.PropertyUtils; import org.junit.Assert; import org.junit.Test; -import org.openmrs.api.impl.AdministrationServiceImpl; -import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; -import org.openmrs.module.webservices.rest.test.Util; import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController; import org.springframework.beans.factory.annotation.Autowired; import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; +import org.openmrs.api.AdministrationService; +import java.util.Map; +import org.springframework.mock.web.MockHttpServletRequest; public class SystemInformationResource1_8Test extends BaseModuleWebContextSensitiveTest { + private AdministrationService administrationService; + @Autowired private MainResourceController mainResourceController; + public String getURI() { + return "systeminformation"; + } + @Test public void testGetAll() throws Exception { - SimpleObject rest = new SimpleObject(); - rest.put("SystemInfo", Context.getAdministrationService().getSystemInformation()); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setMethod("GET"); MockHttpServletResponse response = new MockHttpServletResponse(); - SimpleObject config = mainResourceController.get("systeminformation", new MockHttpServletRequest(), response); - Assert.assertEquals(config, rest); + SimpleObject result = mainResourceController.get(getURI(), request, response); + + Map> systemInfo = result.get("SystemInfo"); + + // Check openmrsInformation + Map openmrsInformation = systemInfo.get("SystemInfo.title.openmrsInformation"); + Assert.assertTrue(systemInfo.containsKey("SystemInfo.title.openmrsInformation")); + // Check openmrsInformation Property + Assert.assertTrue(openmrsInformation.containsKey("SystemInfo.OpenMRSInstallation.systemDate")); + Assert.assertTrue(openmrsInformation.containsKey("SystemInfo.OpenMRSInstallation.systemTime")); + Assert.assertTrue(openmrsInformation.containsKey("SystemInfo.OpenMRSInstallation.openmrsVersion")); + + // Check javaRuntimeEnvironmentInformation + Map javRuntime = systemInfo.get("SystemInfo.title.javaRuntimeEnvironmentInformation"); + Assert.assertTrue(systemInfo.containsKey("SystemInfo.title.javaRuntimeEnvironmentInformation")); + // Check javaRuntimeEnvironmentInformation Property + Assert.assertTrue(javRuntime.containsKey("SystemInfo.JavaRuntimeEnv.operatingSystem")); + Assert.assertTrue(javRuntime.containsKey("SystemInfo.JavaRuntimeEnv.operatingSystemArch")); + Assert.assertTrue(javRuntime.containsKey("SystemInfo.JavaRuntimeEnv.operatingSystemVersion")); + Assert.assertTrue(javRuntime.containsKey("SystemInfo.JavaRuntimeEnv.javaVersion")); + Assert.assertTrue(javRuntime.containsKey("SystemInfo.JavaRuntimeEnv.javaVendor")); + + // Check memoryInformation + Map memoryInformation = systemInfo.get("SystemInfo.title.memoryInformation"); + Assert.assertTrue(systemInfo.containsKey("SystemInfo.title.memoryInformation")); + // Check memoryInformation Property + Assert.assertTrue(memoryInformation.containsKey("SystemInfo.Memory.totalMemory")); + Assert.assertTrue(memoryInformation.containsKey("SystemInfo.Memory.freeMemory")); + Assert.assertTrue(memoryInformation.containsKey("SystemInfo.Memory.maximumHeapSize")); + + // Check dataBaseInformation + Map dataBaseInformation = systemInfo.get("SystemInfo.title.dataBaseInformation"); + Assert.assertTrue(systemInfo.containsKey("SystemInfo.title.dataBaseInformation")); + // Check dataBaseInformation Property + Assert.assertTrue(dataBaseInformation.containsKey("SystemInfo.Database.name")); + Assert.assertTrue(dataBaseInformation.containsKey("SystemInfo.Database.connectionURL")); + Assert.assertTrue(dataBaseInformation.containsKey("SystemInfo.Database.userName")); + Assert.assertTrue(dataBaseInformation.containsKey("SystemInfo.Database.driver")); + Assert.assertTrue(dataBaseInformation.containsKey("SystemInfo.Database.dialect")); + // Check moduleInformation + Map moduleInformation = systemInfo.get("SystemInfo.title.moduleInformation"); + Assert.assertTrue(systemInfo.containsKey("SystemInfo.title.moduleInformation")); + // Check moduleInformation Property + Assert.assertTrue(moduleInformation.containsKey("SystemInfo.Module.repositoryPath")); } }