diff options
Diffstat (limited to 'src/test/java/org/eclipse/openk')
11 files changed, 459 insertions, 0 deletions
diff --git a/src/test/java/org/eclipse/openk/mics/home/common/BackendConfigTest.java b/src/test/java/org/eclipse/openk/mics/home/common/BackendConfigTest.java new file mode 100644 index 0000000..201c25e --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/common/BackendConfigTest.java @@ -0,0 +1,31 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.common; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class BackendConfigTest { + @Test + public void testConfig() { + BackendConfig bc = BackendConfig.getInstance(); + assertEquals( bc.getMicsCentralURL(), "http://localhost:9010/mics/central" ); + assertEquals( bc.getMicsDistributionCluster(), "openK"); + assertEquals( bc.getMicsHealthStateExtraPath(), "healthcheck?pretty=true" ); + BackendConfig.setConfigFileName("backendConfigProduction.json"); + assertEquals( BackendConfig.getConfigFileName(), "backendConfigProduction.json"); + assertEquals( false, BackendConfig.getInstance().isMicsCentralIsHttps()); + } +} diff --git a/src/test/java/org/eclipse/openk/mics/home/common/HttpStatusExceptionTest.java b/src/test/java/org/eclipse/openk/mics/home/common/HttpStatusExceptionTest.java new file mode 100644 index 0000000..664e987 --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/common/HttpStatusExceptionTest.java @@ -0,0 +1,26 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.common; + +import org.apache.http.HttpStatus; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class HttpStatusExceptionTest { + @Test + public void testAll() { + HttpStatusException hse = new HttpStatusException( 200 ); + assertEquals( hse.getHttpStatus(), HttpStatus.SC_OK ); + } +} diff --git a/src/test/java/org/eclipse/openk/mics/home/common/InitBackendConfigTest.java b/src/test/java/org/eclipse/openk/mics/home/common/InitBackendConfigTest.java new file mode 100644 index 0000000..fbc0e97 --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/common/InitBackendConfigTest.java @@ -0,0 +1,53 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.common; + +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +public class InitBackendConfigTest { + + private InitBackendConfig initBackendConfig = new InitBackendConfig(); + + @Test + public void testSetConfigFiles() throws Exception { + Whitebox.invokeMethod(initBackendConfig, "setConfigFiles", "DevLocal"); + } + + private void testGeneric(String environment ) throws Exception { + Whitebox.invokeMethod(initBackendConfig, "setConfigFiles", environment); + } + + @Test + public void testCombinations() throws Exception { + + testGeneric("DevLocal"); + testGeneric("DevLocal"); + + testGeneric("Docker"); + testGeneric("Docker"); + + testGeneric("DevServer"); + testGeneric("DevServer"); + + testGeneric("Custom"); + testGeneric("Custom"); + + testGeneric(null); + testGeneric(null); + + testGeneric(""); + testGeneric(""); + +} +} diff --git a/src/test/java/org/eclipse/openk/mics/home/common/NotificationStatusTest.java b/src/test/java/org/eclipse/openk/mics/home/common/NotificationStatusTest.java new file mode 100644 index 0000000..e6fb159 --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/common/NotificationStatusTest.java @@ -0,0 +1,32 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.common; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class NotificationStatusTest { + + @Test + public void createNotificationStatus() throws Exception { + + assertEquals(0, NotificationStatus.UNKNOWN.id); + assertEquals(1, NotificationStatus.OPEN.id); + assertEquals(2, NotificationStatus.INPROGRESS.id); + assertEquals(3, NotificationStatus.FINISHED.id); + assertEquals(4, NotificationStatus.CLOSED.id); + + } + +} diff --git a/src/test/java/org/eclipse/openk/mics/home/common/util/JsonGeneratorBaseTest.java b/src/test/java/org/eclipse/openk/mics/home/common/util/JsonGeneratorBaseTest.java new file mode 100644 index 0000000..83ce19d --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/common/util/JsonGeneratorBaseTest.java @@ -0,0 +1,76 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.common.util; + +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +import java.util.Date; + +import static org.junit.Assert.assertEquals; + +public class JsonGeneratorBaseTest extends ResourceLoaderBase { + public static class TestPojo { + private String name; + private int number; + private Date date; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + } + + @Test + public void testInputOutput() throws Exception { + Date now = new Date(System.currentTimeMillis()); + TestPojo pojo = new TestPojo(); + pojo.setDate(now); + pojo.setName("Haferkamp"); + pojo.setNumber(6758); + + // call to reach sonar quality gate + Whitebox.invokeConstructor(JsonGeneratorBase.class); + + String jsonString = JsonGeneratorBase.getGson().toJson(pojo); + + TestPojo pojoIncoming = JsonGeneratorBase.getGson().fromJson(jsonString, TestPojo.class); + + assertEquals(pojo.getDate(), pojoIncoming.getDate()); + assertEquals(pojo.getName(), pojoIncoming.getName()); + assertEquals(pojo.getNumber(), pojoIncoming.getNumber()); + } + + +} diff --git a/src/test/java/org/eclipse/openk/mics/home/common/util/ResourceLoaderBaseTest.java b/src/test/java/org/eclipse/openk/mics/home/common/util/ResourceLoaderBaseTest.java new file mode 100644 index 0000000..ebdb533 --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/common/util/ResourceLoaderBaseTest.java @@ -0,0 +1,27 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.common.util; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ResourceLoaderBaseTest { + @Test + public void testloadStringFromResourceError() { + ResourceLoaderBase rlb = new ResourceLoaderBase(); + String str = rlb.loadStringFromResource("UNKNOWN_FILE"); + assertEquals(str, ""); + } +} diff --git a/src/test/java/org/eclipse/openk/mics/home/controller/CentralProxyTest.java b/src/test/java/org/eclipse/openk/mics/home/controller/CentralProxyTest.java new file mode 100644 index 0000000..64d1d7f --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/controller/CentralProxyTest.java @@ -0,0 +1,40 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.controller; + +import org.eclipse.openk.mics.home.common.HttpStatusException; +import org.eclipse.openk.mics.home.communication.RestServiceWrapper; +import org.easymock.EasyMock; +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +import static org.easymock.EasyMock.anyString; +import static org.junit.Assert.assertEquals; + +public class CentralProxyTest { + + @Test + public void testAll() throws HttpStatusException { + RestServiceWrapper rsw = EasyMock.createMock(RestServiceWrapper.class); + EasyMock.expect(rsw.performGetRequest(anyString())).andReturn("fine").anyTimes(); + EasyMock.replay(rsw); + EasyMock.verify(rsw); + CentralProxy cp = new CentralProxy("TEST_URL"); + + Whitebox.setInternalState(cp, "restServiceWrapper", rsw); + + assertEquals( "fine", cp.getHealthState("/abs", + "https", "123.456.789.0", "4711")); + assertEquals( "fine", cp.getServerDistribution("klausDasCluster")); + } +} diff --git a/src/test/java/org/eclipse/openk/mics/home/controller/ResponseBuilderWrapperTest.java b/src/test/java/org/eclipse/openk/mics/home/controller/ResponseBuilderWrapperTest.java new file mode 100644 index 0000000..c168498 --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/controller/ResponseBuilderWrapperTest.java @@ -0,0 +1,41 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.controller; + + +import org.apache.http.HttpStatus; +import org.eclipse.openk.mics.home.common.HttpStatusException; +import org.junit.Test; + +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; + + +public class ResponseBuilderWrapperTest { + @Test + public void testGetResponseBuilder() throws HttpStatusException { + String json = "{ 'ret' : 'OK' }"; + Response.ResponseBuilder rb = ResponseBuilderWrapper.INSTANCE.getResponseBuilder( json ); + Response resp = rb.build(); + assertEquals(resp.getStatus(), HttpStatus.SC_OK ); + } + + @Test + public void testBuildOkResponse() throws HttpStatusException { + String json = "{ 'test' : 'Value' }"; + Response resp = ResponseBuilderWrapper.INSTANCE.buildOKResponse( json ); + assertEquals( resp.getStatus(), HttpStatus.SC_OK ); + + } +} diff --git a/src/test/java/org/eclipse/openk/mics/home/viewmodel/ErrorReturnTest.java b/src/test/java/org/eclipse/openk/mics/home/viewmodel/ErrorReturnTest.java new file mode 100644 index 0000000..6ac0ada --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/viewmodel/ErrorReturnTest.java @@ -0,0 +1,42 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.viewmodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.eclipse.openk.mics.home.common.JsonGeneratorBase; +import org.eclipse.openk.mics.home.common.util.ResourceLoaderBase; +import org.junit.Test; + +public class ErrorReturnTest extends ResourceLoaderBase { + // IMPORTANT TEST!!! + // Make sure, our Interface produces a DEFINED Json! + // Changes in the interface will HOPEFULLY crash here!!! + + @Test + public void TestStructureAgainstJson() { + String json = super.loadStringFromResource("testErrorReturn.json"); + ErrorReturn errRet = JsonGeneratorBase.getGson().fromJson(json, ErrorReturn.class); + assertFalse(errRet.getErrorText().isEmpty()); + assertEquals(errRet.getErrorCode(), 999); + } + + @Test + public void TestSetters() { + ErrorReturn errRet = new ErrorReturn(); + errRet.setErrorCode(1); + errRet.setErrorText("bla bla"); + } + +} diff --git a/src/test/java/org/eclipse/openk/mics/home/viewmodel/ServiceRequestEnvelopeTest.java b/src/test/java/org/eclipse/openk/mics/home/viewmodel/ServiceRequestEnvelopeTest.java new file mode 100644 index 0000000..23a9fe7 --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/viewmodel/ServiceRequestEnvelopeTest.java @@ -0,0 +1,50 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.viewmodel; + + +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class ServiceRequestEnvelopeTest { + + @Test + public void testPojo() { + final String payload = "Testme Accurate"; + ServiceRequestEnvelope env = new ServiceRequestEnvelope(); + env.setHttps(true); + env.setMethod("POST"); + env.setUriFragment("Fraggel"); + env.setServiceName("Salve"); + + ServiceRequestEnvelope.HttpHeader[] headers = new ServiceRequestEnvelope.HttpHeader[2]; + headers[0] = new ServiceRequestEnvelope.HttpHeader(); + headers[0].setAttribute("1stAttr"); + headers[0].setValue("1stValue"); + headers[1] = new ServiceRequestEnvelope.HttpHeader(); + headers[1].setAttribute("2ndAttr"); + headers[1].setValue("2ndValue"); + env.setHeaders(headers); + + assertEquals(true, env.isHttps()); + assertEquals("POST", env.getMethod()); + env.setPayload(payload); + assertEquals(payload, env.getPayload()); + assertEquals("Fraggel", env.getUriFragment()); + assertEquals("Salve", env.getServiceName()); + assertEquals(2, env.getHeaders().length); + assertEquals("2ndAttr", env.getHeaders()[1].getAttribute()); + assertEquals("1stValue", env.getHeaders()[0].getValue()); + } +} diff --git a/src/test/java/org/eclipse/openk/mics/home/viewmodel/VersionInfoTest.java b/src/test/java/org/eclipse/openk/mics/home/viewmodel/VersionInfoTest.java new file mode 100644 index 0000000..8e41e0a --- /dev/null +++ b/src/test/java/org/eclipse/openk/mics/home/viewmodel/VersionInfoTest.java @@ -0,0 +1,41 @@ +/** +****************************************************************************** +* Copyright © 2018 PTA GmbH. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* +* http://www.eclipse.org/legal/epl-v10.html +* +****************************************************************************** +*/ + +package org.eclipse.openk.mics.home.viewmodel; + + +import static org.junit.Assert.assertTrue; + +import org.eclipse.openk.mics.home.common.JsonGeneratorBase; +import org.eclipse.openk.mics.home.common.util.ResourceLoaderBase; +import org.junit.Test; + +public class VersionInfoTest extends ResourceLoaderBase { + // IMPORTANT TEST!!! + // Make sure, our Interface produces a DEFINED Json! + // Changes in the interface will HOPEFULLY crash here!!! + + @Test + public void testStructureAgainstJson() { + String json = super.loadStringFromResource("VersionInfo.json"); + VersionInfo vi = JsonGeneratorBase.getGson().fromJson(json, VersionInfo.class); + + assertTrue(vi.getBackendVersion().equals("0x.0x.xx")); + } + + @Test + public void testSetters() { + VersionInfo vi = new VersionInfo(); + vi.setBackendVersion("222"); + } + +} |