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 new file mode 100644 index 0000000000..eccfeb10ae --- /dev/null +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8.java @@ -0,0 +1,44 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; + +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.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.RequestContext; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.annotation.Resource; +import org.openmrs.module.webservices.rest.web.resource.api.Listable; +import org.openmrs.module.webservices.rest.web.response.ResponseException; + +// the framework requires we specify a supportedClass, even though this shouldn't have one +@Resource(name = RestConstants.VERSION_1 + "/systeminformation", supportedClass = AdministrationServiceImpl.class, supportedOpenmrsVersions = { + "1.10.*", "1.11.*", "1.12.*", "1.8.*", "1.9.*", "2.0.*", "2.1.*" }) +public class SystemInformationResource1_8 implements Listable { + + @Override + public SimpleObject getAll(RequestContext context) throws ResponseException { + SimpleObject rest = new SimpleObject(); + try { + //Push System informations to rest object with Key as SystemInfo + rest.put("SystemInfo", Context.getAdministrationService().getSystemInformation()); + } + catch (Exception ex) { + System.out.println("SystemInfo Resource is getting Error"); + } + return rest; + } + + @Override + public String getUri(Object instance) { + return RestConstants.URI_PREFIX + "/systeminformation"; + } +} 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 new file mode 100644 index 0000000000..8d4637a1bc --- /dev/null +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/SystemInformationResource1_8Test.java @@ -0,0 +1,50 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; + +import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +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.Before; +//import org.junit.Ignore; +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; + +public class SystemInformationResource1_8Test extends BaseModuleWebContextSensitiveTest { + + @Autowired + private MainResourceController mainResourceController; + + @Test + public void testGetAll() throws Exception { + SimpleObject rest = new SimpleObject(); + rest.put("SystemInfo", Context.getAdministrationService().getSystemInformation()); + + // Retrive the System Information using HTTP GET Request + MockHttpServletResponse response = new MockHttpServletResponse(); + SimpleObject config = mainResourceController.get("systeminformation", new MockHttpServletRequest(), response); + + Assert.assertEquals(config, rest); + + } +}