Package net.jini.core.constraint

Examples of net.jini.core.constraint.InvocationConstraints


           
            // 1
            String name = "someMethod";
            Class[] types = new Class[] {int.class, Object.class};
            InvocationConstraint ic = Delegation.YES;
            InvocationConstraints constraints = new InvocationConstraints(
                    ic, null);
            MethodDesc md = callConstructor(testCase, name, types, constraints);
            String result = md.getName();
            if (testCase == case1arg) {
                if (result != null) {
View Full Code Here


            int testCase = cases[i];
            logger.log(Level.INFO, "--> " + testCase);
            String name = "someMethod";
            Class[] types = new Class[] {int.class, Object.class};
            InvocationConstraint ic = Delegation.YES;
            InvocationConstraints constraints = new InvocationConstraints(
                    ic, null);
            MethodDesc md = null;
            Class[] returnedTypes = null;
           
            // 1
View Full Code Here

           
            // 1
            String name1 = "someMethod";
            Class[] types1 = new Class[] {int.class, Object.class};
            InvocationConstraint ic = Delegation.YES;
            InvocationConstraints constraints1 = new InvocationConstraints(
                    ic, null);
            String name2 = "someMethod";
            Class[] types2 = new Class[] {int.class, Object.class};
            InvocationConstraints constraints2 = new InvocationConstraints(
                    ic, null);
            MethodDesc md1 = callConstructor(testCase, name1, types1,
                    constraints1);
            MethodDesc md2 = callConstructor(testCase, name2, types2,
                    constraints2);
            if (!md1.equals(md2)) {
                throw new TestException(
                        "MethodDesc objects should be equal");
            }
           
            // 2
            if ((testCase == case2arg) || (testCase == case3arg)) {
                String name2diff = "anotherMethod";
                md1 = callConstructor(testCase, name1, types1,
                        constraints1);
                md2 = callConstructor(testCase, name2diff, types2,
                        constraints2);
                if (md1.equals(md2)) {
                    throw new TestException(
                            "MethodDesc objects should not be equal");
                }
            }
           
            // 3
            if (testCase == case3arg) {
                Class[] types2diff = new Class[] {long.class, Object.class};
                md1 = callConstructor(testCase, name1, types1,
                        constraints1);
                md2 = callConstructor(testCase, name2, types2diff,
                        constraints2);
                if (md1.equals(md2)) {
                    throw new TestException(
                            "MethodDesc objects should not be equal");
                }
            }
           
            // 4
            if ((testCase == case2arg) || (testCase == case3arg)) {
                InvocationConstraint ic2diff = Delegation.NO;
                InvocationConstraints constraints2diff =
                        new InvocationConstraints(ic2diff, null);
                Class[] types2diff = new Class[] {long.class, Object.class};
                md1 = callConstructor(testCase, name1, types1,
                        constraints1);
                md2 = callConstructor(testCase, name2, types2,
                        constraints2diff);
View Full Code Here

            HashSet prefs = new HashSet();
            reqs.add(ClientAuthentication.YES);
            reqs.add(ClientAuthentication.NO);
            prefs.add(ServerAuthentication.YES);
            prefs.add(ServerAuthentication.NO);
            InvocationConstraints obj1 = new InvocationConstraints(reqs, prefs);
            InvocationConstraints obj2 = new InvocationConstraints(reqs, prefs);
            reqs.add(Confidentiality.YES);
            prefs.add(Confidentiality.NO);
            InvocationConstraints obj3 = new InvocationConstraints(reqs, prefs);

            if (!checker(obj1, obj2, obj3)) {
                throw new TestException(
                        "" + " test failed");
            }
View Full Code Here

     */
    protected void callConstructor(Object tc,
                                   InvocationConstraint req,
                                   InvocationConstraint pref)
            throws TestException {
        InvocationConstraints ic = null;

        try {
            ic = new InvocationConstraints(req, pref);
        } catch (Exception e) {
            logger.log(Level.FINE,
                    "Exception while invoking constructor " + tc.toString()
                    + ":: " + e);
            throw new TestException("Exception while invoking constructor "
                    + tc.toString(), e);
        }

        /*
         * Verify that InvocationConstraints object is created.
         */
        if (ic == null) {
            logger.log(Level.FINE,
                    "InvocationConstraints object hasn't been created");
            throw new TestException("InvocationConstraints object hasn't"
                    + " been created");
        }
        logger.log(Level.FINE, "Returned object: " + ic.toString());

        /*
         * Verify that the first constraint, req, is added as a requirement
         * if it is a non-null value.
         */
        Set reqs = ic.requirements();

        if (req == null) {
            if (!reqs.isEmpty()) {
                String s = "Expected that no requirement has been added when"
                        + " req is null; Really requirements aren't empty";
                logger.log(Level.FINE, s);
                throw new TestException(s);
            }
        } else {
            if (!reqs.contains(req)) {
                String s = "Expected that requirement has been added when req"
                        + " is non-null; Really requirements doesn't contain"
                        + " the specified req";
                logger.log(Level.FINE, s);
                throw new TestException(s);
            }
        }

        /*
         * Verify that the second constraint, pref, is added as a preference
         * if it is a non-null value.
         */
        Set prefs = ic.preferences();

        if (pref == null || pref == req) {
            if (!prefs.isEmpty()) {
                String s = "Expected that no preference has been added"
                        + " when pref is null or is duplicate of req;"
View Full Code Here

                logger.log(Level.FINE, "\tpref[" + i + "]:: " + pref[i]);
            }
        } else {
            logger.log(Level.FINE, "\tpref:: null");
        }
        InvocationConstraints ic = null;

        try {
            ic = new InvocationConstraints(req, pref);
            // If some Exception is expected
            if (ex != null) {
                logger.log(Level.FINE, "Expected Exception type:: " + ex);
                throw new TestException("Instead of " + ex + " no Exception"
                        + " has been thrown while invoking constructor "
                        + tc.toString());
            }
        } catch (Exception e) {
            logger.log(Level.FINE,
                    "Exception while invoking constructor " + tc.toString()
                    + ":: " + e);
            // If no Exception is expected
            if (ex == null) {
                throw new TestException("Exception while invoking constructor "
                        + tc.toString(), e);
            }

            // If some Exception is expected
            if (!ex.equals(e.getClass())) {
                logger.log(Level.FINE, "Expected Exception:: " + ex);
                logger.log(Level.FINE, "Thrown   Exception:: " + e.getClass());
                throw new TestException("Instead of " + ex + " "
                        + e.getClass() + " has been thrown while"
                        + " invoking constructor " + tc.toString());
            } else {
                return;
            }
        }

        /*
         * Verify that InvocationConstraints object is created.
         */
        if (ic == null) {
            logger.log(Level.FINE,
                    "InvocationConstraints object hasn't been created");
            throw new TestException("InvocationConstraints object hasn't"
                    + " been created");
        }
        logger.log(Level.FINE, "Returned object: " + ic.toString());

        /*
         * Verify that the first constraint, req, is added as a requirement
         * if it is a non-null value.
         */
        Set reqs = ic.requirements();

        if (req == null) {
            if (!reqs.isEmpty()) {
                String s = "Expected that no requirement has been added when"
                        + " req is null; Really requirements aren't empty";
                logger.log(Level.FINE, s);
                throw new TestException(s);
            }
        } else {
            for (int i = 0; i < req.length; i++) {
                if (!reqs.contains(req[i])) {
                    String s = "Expected that requirement has been added when"
                            + " req is non-null; Really requirements doesn't"
                            + " contain the specified req";
                    logger.log(Level.FINE, s);
                    throw new TestException(s);
                }
            }
        }

        /*
         * Verify that the second constraint, pref, is added as a preference
         * if it is a non-null value.
         */
        Set prefs = ic.preferences();

        if (pref == null) {
            if (!prefs.isEmpty()) {
                String s = "Expected that no preference has been added"
                        + " when pref is null;"
View Full Code Here

                logger.log(Level.FINE, "\t\t" + it.next());
            }
        } else {
            logger.log(Level.FINE, "\tpref:: null");
        }
        InvocationConstraints ic = null;

        try {
            ic = new InvocationConstraints(req, pref);
            // If some Exception is expected
            if (ex != null) {
                logger.log(Level.FINE, "Expected Exception type:: " + ex);
                throw new TestException("Instead of " + ex + " no Exception"
                        + " has been thrown while invoking constructor "
                        + tc.toString());
            }
        } catch (Exception e) {
            logger.log(Level.FINE,
                    "Exception while invoking constructor " + tc.toString()
                    + ":: " + e);
            // If no Exception is expected
            if (ex == null) {
                throw new TestException("Exception while invoking constructor "
                        + tc.toString(), e);
            }

            // If some Exception is expected
            if (!ex.equals(e.getClass())) {
                logger.log(Level.FINE, "Expected Exception:: " + ex);
                logger.log(Level.FINE, "Thrown   Exception:: " + e.getClass());
                throw new TestException("Instead of " + ex + " "
                        + e.getClass() + " has been thrown while"
                        + " invoking constructor " + tc.toString());
            } else {
                return;
            }
        }

        /*
         * Verify that InvocationConstraints object is created.
         */
        if (ic == null) {
            logger.log(Level.FINE,
                    "InvocationConstraints object hasn't been created");
            throw new TestException("InvocationConstraints object hasn't"
                    + " been created");
        }
        logger.log(Level.FINE, "Returned object: " + ic.toString());

        /*
         * Verify that the first constraint, req, is added as a requirement
         * if it is a non-null value.
         */
        Set reqs = ic.requirements();

        if (req == null) {
            if (!reqs.isEmpty()) {
                String s = "Expected that no requirement has been added when"
                        + " req is null; Really requirements aren't empty";
                logger.log(Level.FINE, s);
                throw new TestException(s);
            }
        } else {
            if (!reqs.equals(req)) {
                String s = "Expected that requirement has been added when"
                        + " req is non-null; Really requirements doesn't"
                        + " contain the specified req";
                logger.log(Level.FINE, s);
                throw new TestException(s);
            }
        }

        /*
         * Verify that the second constraint, pref, is added as a preference
         * if it is a non-null value.
         */
        Set prefs = ic.preferences();

        if (pref == null) {
            if (!prefs.isEmpty()) {
                String s = "Expected that no preference has been added"
                        + " when pref is null;"
View Full Code Here

    // inherit javadoc
    public void run() throws Exception {
        // iterate over normalIntegrityCases
        for (int i = 0; i < normalIntegrityCases.length; i++) {
            logger.log(Level.FINE,"=================================");
            InvocationConstraints constraints = new InvocationConstraints(
                normalIntegrityCases[i][0], normalIntegrityCases[i][1]);
            logger.log(Level.FINE,"integrity test case " + (counter++)
                + ": constraints:" + constraints);
            logger.log(Level.FINE,"");

            iterator.init();
            request.setUnfulfilledConstraintsReturn(constraints);

            try {
                impl.fakeMethod();
                assertion(false);
            } catch (Throwable ignore) {
            }
            requestStream = request.getRequestStream();
            assertion(requestStream.read() == 0x00);
            assertion(requestStream.read() == 0x01);

            checkIntegrityEnforcement(true);
        }

        // iterate over normalNoIntegrityCases
        for (int i = 0; i < normalNoIntegrityCases.length; i++) {
            logger.log(Level.FINE,"=================================");
            InvocationConstraints constraints = new InvocationConstraints(
                normalNoIntegrityCases[i][0], normalNoIntegrityCases[i][1]);
            logger.log(Level.FINE,"no integrity test case " + (counter++)
                + ": constraints:" + constraints);
            logger.log(Level.FINE,"");

            iterator.init();
            request.setUnfulfilledConstraintsReturn(constraints);

            try {
                impl.fakeMethod();
                assertion(false);
            } catch (Throwable ignore) {
            }
            requestStream = request.getRequestStream();
            assertion(requestStream.read() == 0x00);
            assertion(requestStream.read() == 0x00);

            checkIntegrityEnforcement(false);
        }

        // iterate over exceptionCases
        for (int i = 0; i < exceptionCases.length; i++) {
            logger.log(Level.FINE,"=================================");
            InvocationConstraints constraints = new InvocationConstraints(
                exceptionCases[i][0], exceptionCases[i][1]);
            logger.log(Level.FINE,"exception test case " + (counter++)
                + ": constraints:" + constraints);
            logger.log(Level.FINE,"");
View Full Code Here

        /*
         * +++++ TestCase #1 +++++
         */
        reqs.clear();
        prefs.clear();
        tc[0] = new TestCase(new InvocationConstraints(reqs, prefs), true);

        /*
         * +++++ TestCase #2 +++++
         */
        reqs.clear();
        prefs.clear();
        reqs.add(Delegation.YES);
        tc[1] = new TestCase(new InvocationConstraints(reqs, prefs), false);

        /*
         * +++++ TestCase #3 +++++
         */
        reqs.clear();
        prefs.clear();
        prefs.add(Delegation.YES);
        tc[2] = new TestCase(new InvocationConstraints(reqs, prefs), false);

        /*
         * +++++ TestCase #4 +++++
         */
        reqs.clear();
        prefs.clear();
        reqs.add(Delegation.YES);
        prefs.add(Delegation.YES);
        tc[3] = new TestCase(new InvocationConstraints(reqs, prefs), false);
    }
View Full Code Here

     extends AbstractDispatcherTest
{

    // inherit javadoc
    public void run() throws Exception {
        InvocationConstraints checkConstraintsReturn =
            new InvocationConstraints(new InvocationConstraint[]
                {Integrity.YES}, null);
        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": no integrity"
            + ",checkConstraints return: " + checkConstraintsReturn);
        logger.log(Level.FINE,"");

        // initialize FakeInboundRequest
        request = new FakeInboundRequest(methodHash,nullArgs,0x00,0x00);
        request.setCheckConstraintsReturn(checkConstraintsReturn);

        // call dispatch and verify the proper result
        dispatcher.dispatch(impl,request,context);
        response = request.getResponseStream();
        assertion(response.read() == 0x02);
        checkUnmarshallingException(
            new UnsupportedConstraintException(""), response);

        checkConstraintsReturn =
            new InvocationConstraints(new InvocationConstraint[]
                {Integrity.NO, Confidentiality.YES}, null);
        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": integrity"
            + ",checkConstraints return: " + checkConstraintsReturn);
View Full Code Here

TOP

Related Classes of net.jini.core.constraint.InvocationConstraints

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.