Package com.sun.jini.test.spec.config.util

Examples of com.sun.jini.test.spec.config.util.DefaultTestComponent


        FakeConfigurationFile configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        Object data = new DefaultTestComponent();
        Object result = configurationFile.getEntryInternal(
                "com.sun.jini.test.spec.config.util.TestComponent",
                "entry",
                TestComponent.class,
                data);
        if (!(result instanceof TestComponent)) {
            throw new TestException(
                    "Result is not the TestComponent class as was expected");
        }
        TestComponent dtc = (TestComponent) result;
        if (dtc.data != data) {
            throw new TestException(
                    "Data was not delivered properly");
        }

        // 2 - primitive types
        for (int j = 0; j < primitiveCases.length; ++j) {
            Object[] subCase = primitiveCases[j];
            String entryLine = (String) subCase[0];
            Class type = (Class) subCase[1];
            data = subCase[2];
            configurationFile = createCF(
                    testCase,
                    testSubCase,
                    entryLine,
                    null);
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry",
                    type,
                    data);
            if (!(result instanceof Primitive)) {
                throw new TestException(
                        "Result is not the Primitive class as was expected");
            }
            Object value = ((Primitive)result).getValue();
            if (!value.equals(data)) {
                throw new TestException(
                    "getValue returnes invalid value "
                    + value + ", was expected " + data);
            }
        }

        // 3 - unexisted entry
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "unexistEntry",
                    TestComponent.class,
                    data);
            throw new TestException(
                    "NoSuchEntryException should be thrown if"
                    + " no such entry exists");
        } catch (NoSuchEntryException ignore) {
        }

        // 4 - component is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    null,
                    "entry",
                    TestComponent.class,
                    data);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 5 - name is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    null,
                    TestComponent.class,
                    data);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 6 - type is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry",
                    null,
                    data);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 7 - problem occurs creating the object for the entry
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = TestComponent.throwException($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry",
                    TestComponent.class,
View Full Code Here


        FakeConfigurationFile configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        Object data = new DefaultTestComponent();
        Class result = configurationFile.getEntryType(
                "com.sun.jini.test.spec.config.util.TestComponent",
                "entry");
        if (result != TestComponent.class) {
            throw new TestException("Invalid type was returned");
        }

        // 1b - primitive types
        for (int j = 0; j < primitiveCases.length; ++j) {
            Object[] subCase = primitiveCases[j];
            String entryLine = (String) subCase[0];
            Class type = (Class) subCase[1];
            data = subCase[2];
            configurationFile = createCF(
                    testCase,
                    testSubCase,
                    entryLine,
                    null);
            result = configurationFile.getEntryType(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry");
            if (result != type) {
                throw new TestException(
                        "Result type " + result
                        + " is not valid, expected type is " + type);
            }
        }

        // 2 - null case
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = null",
                null);
        result = configurationFile.getEntryType(
                "com.sun.jini.test.spec.config.util.TestComponent",
                "entry");
        if (result != null) {
            throw new TestException("null should be returned");
        }

        // 3 - unexisted entry
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        try {
            result = configurationFile.getEntryType(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "unexistEntry");
            throw new TestException(
                    "NoSuchEntryException should be thrown if"
                    + " no such entry exists");
        } catch (NoSuchEntryException ignore) {
        }

        // 4 - unexisted type
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new UnexistedType()",
                null);
        try {
            result = configurationFile.getEntryType(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry");
            throw new TestException(
                    "ConfigurationException should be thrown if a matching"
                    + " entry is found but a problem occurs determining"
                    + " the type of the entry");
        } catch (ConfigurationException ignore) {
        }

        // 5 - illegal component
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        try {
            result = configurationFile.getEntryType(
                    "com.sun.jini.#%^&",
                    "entry");
            throw new TestException(
                    "ConfigurationException should be thrown if"
                    + " no such entry exists");
        } catch (IllegalArgumentException ignore) {
        }

        // 6 - illegal entry name
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        try {
            result = configurationFile.getEntryType(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "#%^&");
            throw new TestException(
                    "ConfigurationException should be thrown if"
                    + " no such entry exists");
        } catch (IllegalArgumentException ignore) {
        }

        // 7a - name is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        try {
            result = configurationFile.getEntryType(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    null);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 7b - component is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        try {
            result = configurationFile.getEntryType(
                    null,
                    "entry");
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 8a - test that the return value is the static type
        TestComponent.staticEntry = new DefaultTestComponent();
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = TestComponent.staticMethod()",
                null);
        result = configurationFile.getEntryType(
                "com.sun.jini.test.spec.config.util.TestComponent",
                "entry");
        if (result != TestComponent.class) {
            throw new TestException("Invalid type was returned");
        }

        // 8b - test that the return value is the static type
        TestComponent.staticEntry = new DefaultTestComponent();
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = TestComponent.getInterfaceTestComponent()",
                null);
        result = configurationFile.getEntryType(
                "com.sun.jini.test.spec.config.util.TestComponent",
                "entry");
        if (result != InterfaceTestComponent.class) {
            throw new TestException("Invalid type was returned");
        }

        // 8c - test that the return value is the abstract type
        TestComponent.staticEntry = new DefaultTestComponent();
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = TestComponent.getAbstractTestComponent()",
                null);
View Full Code Here

        Object result = null;

        // 1
        FakeAbstractConfiguration conf = new FakeAbstractConfiguration();
        entryName = conf.validEntryName;
        defaultValue = new DefaultTestComponent();
        data = new Object();
        result = callGetEntry(conf,
                testCase,
                componentName,
                entryName,
                TestComponent.class,
                defaultValue,
                data);
        if (!(conf.getComponent().equals(componentName))) {
            throw new TestException(
                    "component argument was not delivered successfully");
        }
        if (!(conf.getName().equals(entryName))) {
            throw new TestException(
                    "name argument was not delivered successfully");
        }
        if (!(conf.getType().equals(TestComponent.class))) {
            throw new TestException(
                    "type argument was not delivered successfully");
        }
        if (testCase == GET_ENTRY_5ARG_CASE
                && !(conf.getData().equals(data))) {
            throw new TestException(
                    "data argument was not delivered successfully");
        }
        if (conf.getReturn() != result) {
            throw new TestException(
                    "getEntry returns invalid object");
        }

        // 2
        if (       testCase == GET_ENTRY_4ARG_CASE
                || testCase == GET_ENTRY_5ARG_CASE) {
            conf = new FakeAbstractConfiguration();
            entryName = "unexistEntry";
            defaultValue = new DefaultTestComponent();
            result = callGetEntry(conf,
                    testCase,
                    componentName,
                    entryName,
                    TestComponent.class,
                    defaultValue,
                    data);
            if (!(result.equals(defaultValue))) {
                throw new TestException(
                        "getEntry should return default test component");
            }
        }

        // 3
        if (       testCase == GET_ENTRY_4ARG_CASE
                || testCase == GET_ENTRY_5ARG_CASE) {
            conf = new FakeAbstractConfiguration();
            entryName = "unexistEntry";
            try {
                result = callGetEntry(conf,
                        testCase,
                        componentName,
                        entryName,
                        TestComponent.class,
                        Configuration.NO_DEFAULT,
                        data);
                throw new TestException(
                        "NoSuchEntryException should be thrown"
                        + " in case of absent entry"
                        + " and dafault value is equal to"
                        + " Configuration.NO_DEFAULT");
            } catch (NoSuchEntryException ignore) {
                logger.log(Level.INFO,
                        "NoSuchEntryException in case of absent entry"
                        + " and dafault value is equal to"
                        + " Configuration.NO_DEFAULT");
            }
        }

        // 4
        for (int j = 0; j < primitiveCases.length; ++j) {
            Object[] subCase = primitiveCases[j];
            logger.log(Level.INFO, "-- subcase: " + subCase[0]);
            entryName = (String) subCase[0];
            Object returnValue = subCase[1];
            defaultValue = subCase[2];
            Class entryType = (Class) subCase[3];
            conf = new FakeAbstractConfiguration();
            result = callGetEntry(conf, testCase, componentName,
                    entryName, entryType, defaultValue, null);
            if (!(result.equals(returnValue))) {
                throw new TestException(
                        "getEntry returns invalid value: " + result);
            }
        }
       
        // 5
        conf = new FakeAbstractConfiguration();
        entryName = conf.validEntryName;
        try {
            result = callGetEntry(conf,
                    testCase,
                    null,
                    entryName,
                    TestComponent.class,
                    Configuration.NO_DEFAULT,
                    null);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " component is null");
        } catch (NullPointerException ignore) {
            logger.log(Level.INFO,
                    "NullPointerException in case of"
                    + " component is null");
        }
       
        // 6
        conf = new FakeAbstractConfiguration();
        try {
            result = callGetEntry(conf,
                    testCase,
                    componentName,
                    null,
                    TestComponent.class,
                    Configuration.NO_DEFAULT,
                    null);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " name is null");
        } catch (NullPointerException ignore) {
            logger.log(Level.INFO,
                    "NullPointerException in case of"
                    + " name is null");
        }
       
        // 7
        conf = new FakeAbstractConfiguration();
        entryName = conf.validEntryName;
        try {
            result = callGetEntry(conf,
                    testCase,
                    componentName,
                    entryName,
                    null,
                    Configuration.NO_DEFAULT,
                    null);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " type is null");
        } catch (NullPointerException ignore) {
            logger.log(Level.INFO,
                    "NullPointerException in case of"
                    + " type is null");
        }
       
        // 8
        conf = new FakeAbstractConfiguration();
        entryName = conf.validEntryName;
        try {
            result = callGetEntry(conf,
                    testCase,
                    "invalid qualified identifier",
                    entryName,
                    TestComponent.class,
                    Configuration.NO_DEFAULT,
                    null);
            throw new TestException(
                    "IllegalArgumentException should be thrown if"
                    + " component is not valid qualified identifier");
        } catch (IllegalArgumentException ignore) {
            logger.log(Level.INFO,
                    "IllegalArgumentException in case of"
                    + " component is not valid qualified identifier");
        }
       
        // 9
        conf = new FakeAbstractConfiguration();
        entryName = conf.validEntryName;
        try {
            result = callGetEntry(conf,
                    testCase,
                    componentName,
                    "invalid identifier",
                    TestComponent.class,
                    Configuration.NO_DEFAULT,
                    null);
            throw new TestException(
                    "IllegalArgumentException should be thrown if"
                    + " name is not valid identifier");
        } catch (IllegalArgumentException ignore) {
            logger.log(Level.INFO,
                    "IllegalArgumentException in case of"
                    + " name is not valid identifier");
        }
       
        // 10
        if (       testCase == GET_ENTRY_4ARG_CASE
                || testCase == GET_ENTRY_5ARG_CASE) {
            conf = new FakeAbstractConfiguration();
            entryName = conf.validEntryName;
            try {
                result = callGetEntry(conf,
                        testCase,
                        componentName,
                        entryName,
                        TestComponent.class,
                        new Object(),
                        null);
                throw new TestException(
                        "IllegalArgumentException should be thrown if"
                        + " defaultValue is not of the right type");
            } catch (IllegalArgumentException ignore) {
                logger.log(Level.INFO,
                        "IllegalArgumentException in case of"
                        + " defaultValue is not of the right type");
            }
        }

        // 11
        final Throwable[] exceptionList = {
              new java.lang.ArrayIndexOutOfBoundsException(),
              new java.lang.SecurityException(),
              new java.lang.NullPointerException(),
              new java.lang.ArithmeticException(),
              new java.lang.ArrayStoreException(),
              new java.lang.ClassCastException(),
              new java.util.EmptyStackException(),
              new java.lang.IllegalArgumentException(),
              new java.lang.IllegalMonitorStateException(),
              new java.lang.IllegalStateException(),
              new java.lang.IndexOutOfBoundsException(),
              new java.util.MissingResourceException("","",""),
              new java.lang.NegativeArraySizeException(),
              new java.util.NoSuchElementException(),
              new java.lang.NullPointerException(),
              new java.security.ProviderException(),
              new java.lang.SecurityException(),
              new java.lang.reflect.UndeclaredThrowableException(null),
              new java.lang.UnsupportedOperationException() };
        for (int e = 0; e < exceptionList.length; ++e) {
            Throwable testException = exceptionList[e];
            logger.log(Level.INFO, "-- subcase: " + testException);
            conf = new FakeAbstractConfiguration();
            conf.setException(testException);
            entryName = conf.validEntryName;
            defaultValue = new DefaultTestComponent();
            data = new Object();
            try {
                result = callGetEntry(conf, testCase, componentName, entryName,
                   TestComponent.class, defaultValue, data);
                throw new TestException(
                        "getEntry should throw an exception");
            } catch (ConfigurationException ce) {
                if (!(ce.getCause().equals(testException))) {
                    throw new TestException(
                            "getEntry throws an exception with invalid cause");
                }
            }
        }
        conf.setException(null);

        // 12
        final Throwable[] exceptionList2 = {
              new ConfigurationException(""),
              new ConfigurationNotFoundException(""),
              new NoSuchEntryException(""),
              new Error() };
        for (int e = 0; e < exceptionList2.length; ++e) {
            Throwable testException = exceptionList2[e];
            logger.log(Level.INFO, "-- subcase: " + testException);
            conf = new FakeAbstractConfiguration();
            conf.setException(testException);
            entryName = conf.validEntryName;
            defaultValue = Configuration.NO_DEFAULT;
            data = new Object();
            try {
                result = callGetEntry(conf, testCase, componentName, entryName,
                   TestComponent.class, defaultValue, data);
                throw new TestException(
                        "getEntry should throw an exception");
            } catch (ConfigurationException ce) {
                if (!(ce.equals(testException))) {
                    throw new TestException(
                            "getEntry throws invalid exception");
                }
            } catch (Error er) {
                if (!(er.equals(testException))) {
                    throw new TestException(
                            "getEntry throws an exception with invalid cause");
                }
            }
        }
        conf.setException(null);

        // 13
        conf = new FakeAbstractConfiguration();
        conf.setReturn(new Object());
        entryName = conf.validEntryName;
        defaultValue = new DefaultTestComponent();
        data = new Object();
        try {
            result = callGetEntry(conf,
                    testCase,
                    componentName,
View Full Code Here

        FakeConfigurationFile configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        Object data = new DefaultTestComponent();
        Object result = configurationFile.getEntryInternal(
                "com.sun.jini.test.spec.config.util.TestComponent",
                "entry",
                TestComponent.class,
                data);
        if (!(result instanceof TestComponent)) {
            throw new TestException(
                    "Result is not the TestComponent class as was expected");
        }
        TestComponent dtc = (TestComponent) result;
        if (dtc.data != data) {
            throw new TestException(
                    "Data was not delivered properly");
        }

        // 2 - primitive types
        for (int j = 0; j < primitiveCases.length; ++j) {
            Object[] subCase = primitiveCases[j];
            String entryLine = (String) subCase[0];
            Class type = (Class) subCase[1];
            data = subCase[2];
            configurationFile = createCF(
                    testCase,
                    testSubCase,
                    entryLine,
                    null);
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry",
                    type,
                    data);
            if (!(result instanceof Primitive)) {
                throw new TestException(
                        "Result is not the Primitive class as was expected");
            }
            Object value = ((Primitive)result).getValue();
            if (!value.equals(data)) {
                throw new TestException(
                    "getValue returnes invalid value "
                    + value + ", was expected " + data);
            }
        }

        // 3 - unexisted entry
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "unexistEntry",
                    TestComponent.class,
                    data);
            throw new TestException(
                    "NoSuchEntryException should be thrown if"
                    + " no such entry exists");
        } catch (NoSuchEntryException ignore) {
        }

        // 4 - component is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    null,
                    "entry",
                    TestComponent.class,
                    data);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 5 - name is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    null,
                    TestComponent.class,
                    data);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 6 - type is null
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = new TestComponent($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry",
                    null,
                    data);
            throw new TestException(
                    "NullPointerException should be thrown if"
                    + " no such entry exists");
        } catch (NullPointerException ignore) {
        }

        // 7 - problem occurs creating the object for the entry
        configurationFile = createCF(
                testCase,
                testSubCase,
                "entry = TestComponent.throwException($data)",
                null);
        data = new DefaultTestComponent();
        try {
            result = configurationFile.getEntryInternal(
                    "com.sun.jini.test.spec.config.util.TestComponent",
                    "entry",
                    TestComponent.class,
View Full Code Here

TOP

Related Classes of com.sun.jini.test.spec.config.util.DefaultTestComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.