Search in sources :

Example 1 with TestTarget

use of org.eclipse.kura.test.annotation.TestTarget in project kura by eclipse.

the class SystemServiceTest method testGetPrimaryMacAddress.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testGetPrimaryMacAddress() {
    String actual = systemService.getPrimaryMacAddress();
    System.out.println("MAC: " + actual);
    Pattern regex = Pattern.compile("[0-9a-fA-F:]{12}");
    Matcher match = regex.matcher(actual);
    assertEquals("getPrimaryMacAddress() length", 17, actual.length());
    assertTrue("getPrimaryMacAddress() is string with colons", match.find());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 2 with TestTarget

use of org.eclipse.kura.test.annotation.TestTarget in project kura by eclipse.

the class XmlUtilTest method testXmlComponentConfigurationsUnmarshalling.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testXmlComponentConfigurationsUnmarshalling() {
    try {
        XmlComponentConfigurations xmlComponentConfigurations = getSampleXmlComponentConfigurationsObject();
        // test String unmarshalling
        String marshalledString = org.eclipse.kura.core.configuration.util.XmlUtil.marshal(xmlComponentConfigurations);
        Object unmarshalledObjectFromString = org.eclipse.kura.core.configuration.util.XmlUtil.unmarshal(marshalledString, XmlComponentConfigurations.class);
        Assert.assertTrue(String.format(differentInstanceMessage, XmlComponentConfigurations.class, unmarshalledObjectFromString.getClass()), unmarshalledObjectFromString instanceof XmlComponentConfigurations);
        XmlComponentConfigurations outputXmlComponentConfigurations = (XmlComponentConfigurations) unmarshalledObjectFromString;
        assertValuesForEquality(pid, xmlComponentConfigurations.getConfigurations().get(0).getPid(), outputXmlComponentConfigurations.getConfigurations().get(0).getPid(), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), false);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), false);
        // test Reader unmarshalling
        Reader marshalledStringReader = new StringReader(marshalledString);
        Object unmarshalledObjectFromStringReader = org.eclipse.kura.core.configuration.util.XmlUtil.unmarshal(marshalledStringReader, XmlComponentConfigurations.class);
        Assert.assertTrue(String.format(differentInstanceMessage, XmlComponentConfigurations.class, unmarshalledObjectFromStringReader.getClass()), unmarshalledObjectFromStringReader instanceof XmlComponentConfigurations);
        outputXmlComponentConfigurations = (XmlComponentConfigurations) unmarshalledObjectFromStringReader;
        assertValuesForEquality(pid, xmlComponentConfigurations.getConfigurations().get(0).getPid(), outputXmlComponentConfigurations.getConfigurations().get(0).getPid(), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("int"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("long"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("string"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("boolean"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("double"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("float"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("char"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("short"), true);
        assertValuesForEquality(hashmapValues, xmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), outputXmlComponentConfigurations.getConfigurations().get(0).getConfigurationProperties().get("byte"), true);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 3 with TestTarget

use of org.eclipse.kura.test.annotation.TestTarget in project kura by eclipse.

the class XmlUtilTest method testXmlDeploymentPackagesMarshalling.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testXmlDeploymentPackagesMarshalling() {
    try {
        XmlDeploymentPackages xmlDeploymentPackages = getSampleXmlDeploymentPackagesObject();
        String marshalledString = XmlUtil.marshal(xmlDeploymentPackages);
        Assert.assertTrue(String.format(missingItemsMessage, xmlDeploymentPackages.getDeploymentPackages()[0].getName()), marshalledString.contains(xmlDeploymentPackages.getDeploymentPackages()[0].getName()));
        Assert.assertTrue(String.format(missingItemsMessage, xmlDeploymentPackages.getDeploymentPackages()[0].getVersion()), marshalledString.contains(xmlDeploymentPackages.getDeploymentPackages()[0].getVersion()));
        Assert.assertTrue(String.format(missingItemsMessage, xmlDeploymentPackages.getDeploymentPackages()[0].getBundleInfos()[0].getName()), marshalledString.contains(xmlDeploymentPackages.getDeploymentPackages()[0].getBundleInfos()[0].getName()));
        Assert.assertTrue(String.format(missingItemsMessage, xmlDeploymentPackages.getDeploymentPackages()[0].getBundleInfos()[0].getVersion()), marshalledString.contains(xmlDeploymentPackages.getDeploymentPackages()[0].getBundleInfos()[0].getVersion()));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 4 with TestTarget

use of org.eclipse.kura.test.annotation.TestTarget in project kura by eclipse.

the class XmlUtilTest method testXmlSnapshotIdResultMarshalling.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void testXmlSnapshotIdResultMarshalling() {
    try {
        XmlSnapshotIdResult xmlSnapshotIdResult = getSampleXmlSnapshotIdResultObject();
        String marshalledString = org.eclipse.kura.core.configuration.util.XmlUtil.marshal(xmlSnapshotIdResult);
        for (Long value : xmlSnapshotIdResult.getSnapshotIds()) {
            Assert.assertTrue(String.format(missingItemsMessage, value), marshalledString.contains(Long.toString(value)));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XmlSnapshotIdResult(org.eclipse.kura.core.configuration.XmlSnapshotIdResult) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 5 with TestTarget

use of org.eclipse.kura.test.annotation.TestTarget in project kura by eclipse.

the class CloudDeploymentHandlerTest method testGetPackages.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
@Ignore
public void testGetPackages() throws Exception {
    assertTrue(s_cloudCallService.isConnected());
    DeploymentPackage dp = s_deploymentAdmin.getDeploymentPackage(LOCAL_DP_NAME);
    if (dp == null) {
        s_logger.warn("Getting dp");
        InputStream is = getTestDpUrl().openStream();
        dp = s_deploymentAdmin.installDeploymentPackage(is);
    }
    StringBuilder sb = new StringBuilder(CloudletTopic.Method.GET.toString()).append("/").append(CloudDeploymentHandlerV2.RESOURCE_PACKAGES);
    KuraResponsePayload resp = s_cloudCallService.call(CloudDeploymentHandlerV2.APP_ID, sb.toString(), null, 5000);
    assertEquals(KuraResponsePayload.RESPONSE_CODE_OK, resp.getResponseCode());
    String s = new String(resp.getBody());
    // XmlDeploymentPackages xmlPackages = XmlUtil.unmarshal(s, XmlDeploymentPackages.class);
    XmlDeploymentPackages xmlPackages = CoreTestXmlUtil.unmarshal(s, XmlDeploymentPackages.class);
    XmlDeploymentPackage[] packages = xmlPackages.getDeploymentPackages();
    XmlDeploymentPackage xmlDp = null;
    if (packages != null) {
        for (int i = 0; i < packages.length; i++) {
            if (packages[i].getName().equals(LOCAL_DP_NAME)) {
                xmlDp = packages[i];
                break;
            }
        }
    }
    assertNotNull(xmlDp);
    assertEquals(LOCAL_DP_VERSION, xmlDp.getVersion());
    XmlBundleInfo[] bundleInfos = xmlDp.getBundleInfos();
    assertEquals(1, bundleInfos.length);
    assertEquals(LOCAL_BUNDLE_NAME, bundleInfos[0].getName());
    assertEquals(LOCAL_BUNDLE_VERSION, bundleInfos[0].getVersion());
}
Also used : InputStream(java.io.InputStream) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) KuraResponsePayload(org.eclipse.kura.message.KuraResponsePayload) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages) Ignore(org.junit.Ignore) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Aggregations

TestTarget (org.eclipse.kura.test.annotation.TestTarget)29 Test (org.junit.Test)20 File (java.io.File)9 FileReader (java.io.FileReader)8 FileOutputStream (java.io.FileOutputStream)7 PrintWriter (java.io.PrintWriter)7 KuraResponsePayload (org.eclipse.kura.message.KuraResponsePayload)6 ArrayList (java.util.ArrayList)4 XmlComponentConfigurations (org.eclipse.kura.core.configuration.XmlComponentConfigurations)4 XmlDeploymentPackage (org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage)4 KuraPayload (org.eclipse.kura.message.KuraPayload)4 AfterClass (org.junit.AfterClass)4 BeforeClass (org.junit.BeforeClass)4 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)4 InputStream (java.io.InputStream)3 ComponentConfigurationImpl (org.eclipse.kura.core.configuration.ComponentConfigurationImpl)3 StringReader (java.io.StringReader)2 HashMap (java.util.HashMap)2 KuraException (org.eclipse.kura.KuraException)2 XmlSnapshotIdResult (org.eclipse.kura.core.configuration.XmlSnapshotIdResult)2