Search in sources :

Example 6 with ExtendedTypeCollectionEnumerationInTypeCollection

use of joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection in project joynr by bmwcarit.

the class IltProvider method methodWithSingleEnumParameters.

/*
     * methodWithSingleEnumParameters
     *
     * return fixed value for now
     */
@Override
public Promise<MethodWithSingleEnumParametersDeferred> methodWithSingleEnumParameters(ExtendedEnumerationWithPartlyDefinedValues enumerationArg) {
    logger.warn("***************************************************");
    logger.warn("* IltProvider.methodWithSingleEnumParameters called");
    logger.warn("***************************************************");
    MethodWithSingleEnumParametersDeferred deferred = new MethodWithSingleEnumParametersDeferred();
    // check input parameter
    if (enumerationArg != ExtendedEnumerationWithPartlyDefinedValues.ENUM_2_VALUE_EXTENSION_FOR_ENUM_WITHOUT_DEFINED_VALUES) {
        logger.warn("methodWithSingleEnumParameters: invalid argument enumerationArg");
        deferred.reject(new ProviderRuntimeException("methodWithSingleEnumParameters: received wrong argument"));
        return new Promise<MethodWithSingleEnumParametersDeferred>(deferred);
    }
    // prepare output parameter
    ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut = ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION;
    deferred.resolve(enumerationOut);
    return new Promise<MethodWithSingleEnumParametersDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 7 with ExtendedTypeCollectionEnumerationInTypeCollection

use of joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection in project joynr by bmwcarit.

the class IltStringBroadcastFilter method filter.

@Override
public boolean filter(String stringOut, String[] stringArrayOut, ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut, StructWithStringArray structWithStringArrayOut, StructWithStringArray[] structWithStringArrayArrayOut, TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastFilterParameters filterParameters) {
    LOG.info("IltStringBroadcastFilter: invoked");
    // check output parameter contents
    if (!IltUtil.checkStringArray(stringArrayOut)) {
        LOG.info("IltStringBroadcastFilter: invalid stringArrayOut value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (enumerationOut != ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION) {
        LOG.info("IltStringBroadcastFilter: invalid enumerationOut value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (!IltUtil.checkStructWithStringArray(structWithStringArrayOut)) {
        LOG.info("IltStringBroadcastFilter: invalid structWithStringArrayOut value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (!IltUtil.checkStructWithStringArrayArray(structWithStringArrayArrayOut)) {
        LOG.info("IltStringBroadcastFilter: invalid structWithStringArrayArrayOut value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    // check filter parameter contents
    // variables to store deserialized values
    String[] stringArrayOfInterest;
    ExtendedTypeCollectionEnumerationInTypeCollection enumerationOfInterest;
    StructWithStringArray structWithStringArrayOfInterest;
    StructWithStringArray[] structWithStringArrayArrayOfInterest;
    try {
        stringArrayOfInterest = jsonSerializer.readValue(filterParameters.getStringArrayOfInterest(), String[].class);
    } catch (IOException e) {
        LOG.info("IltStringBroadcastFilter: got exception while deserializing stringArrayOfInterest");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (!IltUtil.checkStringArray(stringArrayOfInterest)) {
        LOG.info("IltStringBroadcastFilter: invalid stringArrayOfInterest filter parameter value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    try {
        enumerationOfInterest = jsonSerializer.readValue(filterParameters.getEnumerationOfInterest(), ExtendedTypeCollectionEnumerationInTypeCollection.class);
    } catch (IOException e) {
        LOG.info("IltStringBroadcastFilter: got exception while deserializing enumerationOfInterest");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (enumerationOfInterest != ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION) {
        LOG.info("IltStringBroadcastFilter: invalid enumerationOfInterest filter parameter value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    try {
        structWithStringArrayOfInterest = jsonSerializer.readValue(filterParameters.getStructWithStringArrayOfInterest(), StructWithStringArray.class);
    } catch (IOException e) {
        LOG.info("IltStringBroadcastFilter: got exception while deserializing structWithStringArrayOfInterest");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (!IltUtil.checkStructWithStringArray(structWithStringArrayOfInterest)) {
        LOG.info("IltStringBroadcastFilter: invalid structWithStringArrayOfInterest filter parameter value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    try {
        structWithStringArrayArrayOfInterest = jsonSerializer.readValue(filterParameters.getStructWithStringArrayArrayOfInterest(), StructWithStringArray[].class);
    } catch (IOException e) {
        LOG.info("IltStringBroadcastFilter: got exception while deserializing structWithStringArrayOfInterest");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    if (!IltUtil.checkStructWithStringArrayArray(structWithStringArrayArrayOfInterest)) {
        LOG.info("IltStringBroadcastFilter: invalid structWithStringArrayArrayOfInterest filter parameter value");
        LOG.info("IltStringBroadcastFilter: FAILED");
        return false;
    }
    // decision for publication is made based on stringOfInterest
    if (stringOut.equals(filterParameters.getStringOfInterest())) {
        LOG.info("IltStringBroadcastFilter: OK - publication should be sent");
        return true;
    } else {
        LOG.info("IltStringBroadcastFilter: OK - publication should NOT Be sent");
        return false;
    }
}
Also used : ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) IOException(java.io.IOException) StructWithStringArray(joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray)

Example 8 with ExtendedTypeCollectionEnumerationInTypeCollection

use of joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection in project joynr by bmwcarit.

the class IltConsumerMulticastSubscriptionTest method doNotReceivePublicationsForOtherPartitions.

@Test
public void doNotReceivePublicationsForOtherPartitions() {
    String[] subscribeToPartitions = new String[] { "partitions0", "partitions1" };
    String[] broadcastPartitions = new String[] { "otherPartition" };
    try {
        BroadcastWithSingleEnumerationParameterBroadcastAdapter adapter = new BroadcastWithSingleEnumerationParameterBroadcastAdapter() {

            @Override
            public void onReceive(ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut) {
                LOG.info(name.getMethodName() + " - callback - got broadcast");
                subscribeBroadcastWithSingleEnumerationParameterCallbackResult = true;
                subscribeBroadcastWithSingleEnumerationParameterCallbackDone = true;
                synchronized (callbackCalledSemaphore) {
                    callbackCalledSemaphore.notify();
                }
            }

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithSingleEnumerationParameterCallbackResult = false;
                subscribeBroadcastWithSingleEnumerationParameterCallbackDone = true;
                synchronized (callbackCalledSemaphore) {
                    callbackCalledSemaphore.notify();
                }
            }
        };
        Future<String> subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithSingleEnumerationParameterBroadcast(adapter, new MulticastSubscriptionQos(), subscribeToPartitions);
        String subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        LOG.info(name.getMethodName() + " - Invoking fire method with not matching partitions");
        testInterfaceProxy.methodToFireBroadcastWithSingleEnumerationParameter(broadcastPartitions);
        synchronized (callbackCalledSemaphore) {
            callbackCalledSemaphore.wait(2000);
        }
        Assert.assertEquals(false, subscribeBroadcastWithSingleEnumerationParameterCallbackDone);
        LOG.info(name.getMethodName() + " - Invoking fire method with matching partitions");
        testInterfaceProxy.methodToFireBroadcastWithSingleEnumerationParameter(subscribeToPartitions);
        synchronized (callbackCalledSemaphore) {
            callbackCalledSemaphore.wait(1000);
        }
        Assert.assertEquals(true, subscribeBroadcastWithSingleEnumerationParameterCallbackDone);
        Assert.assertEquals(true, subscribeBroadcastWithSingleEnumerationParameterCallbackResult);
        LOG.info(name.getMethodName() + " - received expected broadcast");
        testInterfaceProxy.unsubscribeFromBroadcastWithSingleEnumerationParameterBroadcast(subscriptionId);
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
    }
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) BroadcastWithSingleEnumerationParameterBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithSingleEnumerationParameterBroadcastAdapter) ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) SubscriptionException(io.joynr.exceptions.SubscriptionException) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Test(org.junit.Test)

Example 9 with ExtendedTypeCollectionEnumerationInTypeCollection

use of joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection in project joynr by bmwcarit.

the class IltConsumerSyncMethodTest method callMethodWithSingleEnumParameters.

@Test
public void callMethodWithSingleEnumParameters() {
    LOG.info(name.getMethodName() + "");
    try {
        ExtendedEnumerationWithPartlyDefinedValues enumerationArg = ExtendedEnumerationWithPartlyDefinedValues.ENUM_2_VALUE_EXTENSION_FOR_ENUM_WITHOUT_DEFINED_VALUES;
        ExtendedTypeCollectionEnumerationInTypeCollection result;
        result = testInterfaceProxy.methodWithSingleEnumParameters(enumerationArg);
        if (result == null) {
            fail(name.getMethodName() + " - FAILED - got no result");
            return;
        }
        if (result != ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION) {
            fail(name.getMethodName() + " - FAILED - got invalid result");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) ExtendedEnumerationWithPartlyDefinedValues(joynr.interlanguagetest.namedTypeCollection2.ExtendedEnumerationWithPartlyDefinedValues) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 10 with ExtendedTypeCollectionEnumerationInTypeCollection

use of joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection in project joynr by bmwcarit.

the class IltConsumerFilteredBroadcastSubscriptionTest method callSubscribeBroadcastWithFiltering.

@SuppressWarnings("checkstyle:methodlength")
@Test
public void callSubscribeBroadcastWithFiltering() {
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    int minIntervalMs = 0;
    int maxIntervalMs = 10000;
    long validityMs = 60000;
    int alertAfterIntervalMs = 20000;
    int publicationTtlMs = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
    boolean result;
    LOG.info(name.getMethodName() + "");
    try {
        BroadcastWithFilteringBroadcastFilterParameters filterParameters = new BroadcastWithFilteringBroadcastFilterParameters();
        String stringOfInterst = "fireBroadcast";
        filterParameters.setStringOfInterest(stringOfInterst);
        String[] stringArrayOfInterest = IltUtil.createStringArray();
        String json;
        try {
            LOG.info(name.getMethodName() + " - objectMapper is " + objectMapper);
            LOG.info(name.getMethodName() + " - objectMapper stringArrayOfInterest " + stringArrayOfInterest);
            json = objectMapper.writeValueAsString(stringArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing stringArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStringArrayOfInterest(json);
        ExtendedTypeCollectionEnumerationInTypeCollection enumerationOfInterest = ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION;
        try {
            json = objectMapper.writeValueAsString(enumerationOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing enumerationOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setEnumerationOfInterest(json);
        StructWithStringArray structWithStringArrayOfInterest = IltUtil.createStructWithStringArray();
        try {
            json = objectMapper.writeValueAsString(structWithStringArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing structWithStringArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStructWithStringArrayOfInterest(json);
        StructWithStringArray[] structWithStringArrayArrayOfInterest = IltUtil.createStructWithStringArrayArray();
        try {
            json = objectMapper.writeValueAsString(structWithStringArrayArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing structWithStringArrayArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStructWithStringArrayArrayOfInterest(json);
        subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithFilteringBroadcast(new BroadcastWithFilteringBroadcastAdapter() {

            @Override
            public void onReceive(String stringOut, String[] stringArrayOut, ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut, StructWithStringArray structWithStringArrayOut, StructWithStringArray[] structWithStringArrayArrayOut) {
                LOG.info(name.getMethodName() + " - callback - got broadcast");
                if (!IltUtil.checkStringArray(stringArrayOut)) {
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (enumerationOut != ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (!IltUtil.checkStructWithStringArray(structWithStringArrayOut)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (!IltUtil.checkStructWithStringArrayArray(structWithStringArrayArrayOut)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else {
                    LOG.info(name.getMethodName() + " - callback - content OK");
                    subscribeBroadcastWithFilteringCallbackResult = true;
                }
                subscribeBroadcastWithFilteringCallbackDone = true;
            }

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithFilteringCallbackResult = false;
                subscribeBroadcastWithFilteringCallbackDone = true;
            }
        }, subscriptionQos, filterParameters);
        subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        LOG.info(name.getMethodName() + " - Waiting one second");
        Thread.sleep(1000);
        LOG.info(name.getMethodName() + " - Wait done, invoking fire method");
        String stringArg = "fireBroadcast";
        testInterfaceProxy.methodToFireBroadcastWithFiltering(stringArg);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // should have been called ahead anyway
        if (subscribeBroadcastWithFilteringCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (!subscribeBroadcastWithFilteringCallbackDone) {
            fail(name.getMethodName() + " - FAILED - callback did not get called in time");
            result = false;
        } else if (subscribeBroadcastWithFilteringCallbackResult) {
            LOG.info(name.getMethodName() + " - callback got called and received expected publication");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called but received unexpected error or publication content");
            result = false;
        }
        // get out, if first test run failed
        if (result == false) {
            return;
        }
        // reset counter for 2nd test
        subscribeBroadcastWithFilteringCallbackResult = false;
        subscribeBroadcastWithFilteringCallbackDone = false;
        LOG.info(name.getMethodName() + " - invoking fire method with wrong stringArg");
        stringArg = "doNotfireBroadcast";
        testInterfaceProxy.methodToFireBroadcastWithFiltering(stringArg);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // should have been called ahead anyway
        if (subscribeBroadcastWithFilteringCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (!subscribeBroadcastWithFilteringCallbackDone) {
            LOG.info(name.getMethodName() + " - callback did not get called in time (expected)");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called unexpectedly");
            result = false;
        }
        // try to unsubscribe
        try {
            testInterfaceProxy.unsubscribeFromBroadcastWithFilteringBroadcast(subscriptionId);
            LOG.info(name.getMethodName() + " - unsubscribe successful");
        } catch (Exception e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
            result = false;
        }
        if (!result) {
            LOG.info(name.getMethodName() + " - FAILED");
        } else {
            LOG.info(name.getMethodName() + " - OK");
        }
        return;
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);
        printWriter.flush();
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + stringWriter.toString());
        return;
    }
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) BroadcastWithFilteringBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastAdapter) ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StringWriter(java.io.StringWriter) StructWithStringArray(joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray) BroadcastWithFilteringBroadcastFilterParameters(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastFilterParameters) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Aggregations

ExtendedTypeCollectionEnumerationInTypeCollection (joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection)13 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)8 Test (org.junit.Test)6 Promise (io.joynr.provider.Promise)4 ApplicationException (joynr.exceptions.ApplicationException)4 Enumeration (joynr.interlanguagetest.Enumeration)4 StructWithStringArray (joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray)4 ExtendedEnumerationWithPartlyDefinedValues (joynr.interlanguagetest.namedTypeCollection2.ExtendedEnumerationWithPartlyDefinedValues)4 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 DeferredVoid (io.joynr.provider.DeferredVoid)2 MethodWithMultipleEnumParametersReturned (joynr.interlanguagetest.TestInterfaceSync.MethodWithMultipleEnumParametersReturned)2 ExtendedExtendedEnumeration (joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedEnumeration)2 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)1 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)1