Package net.jini.constraint

Examples of net.jini.constraint.BasicMethodConstraints


        ProxyTrustInvocationHandler ptih = createPTIH(main, boot);
        Object proxy = ProxyTrustUtil.newProxyInstance(
                new RMCTEImpl(), ptih);
        Method m = RemoteMethodControl.class.getDeclaredMethod(
                "setConstraints", new Class[] { MethodConstraints.class });
        MethodConstraints mc = new BasicMethodConstraints(
                new InvocationConstraints(
                    new InvocationConstraint[] { ClientAuthentication.YES },
                    null));
        Object res = ptihInvoke(ptih, proxy, m, new Object[] { mc });
View Full Code Here


                    + " as expected.");
        }
        proxy = new RMCImpl();
        m = RemoteMethodControl.class.getDeclaredMethod(
                "setConstraints", new Class[] { MethodConstraints.class });
        MethodConstraints mc = new BasicMethodConstraints(
                new InvocationConstraints(
                    new InvocationConstraint[] { ClientAuthentication.YES },
                    null));

        try {
View Full Code Here

    static MethodDesc desc(String n, Class[] t) {
  return new MethodDesc(n, t, sc);
    }

    static void match(Method m, MethodDesc desc) {
  BasicMethodConstraints mc =
      new BasicMethodConstraints(new MethodDesc[]{desc});
  if (mc.getConstraints(m) != desc.getConstraints()) {
      throw new RuntimeException("failed to match");
  }
    }
View Full Code Here

      throw new RuntimeException("failed to match");
  }
    }

    static void nomatch(Method m, MethodDesc desc) {
  BasicMethodConstraints mc =
      new BasicMethodConstraints(new MethodDesc[]{desc});
  if (!mc.getConstraints(m).isEmpty()) {
      throw new RuntimeException("incorrectly matched");
  }
    }
View Full Code Here

        InvocationConstraints constraints = new InvocationConstraints(
                ic, null);
        MethodDesc methodDesc1 = new MethodDesc(name, constraints);
        MethodDesc methodDesc2 = new MethodDesc(constraints);
        MethodDesc [] descs = {methodDesc1, methodDesc2};
        BasicMethodConstraints bmc1 = new BasicMethodConstraints(descs);
        BasicMethodConstraints bmc2 = new BasicMethodConstraints(descs);
        if (!bmc1.equals(bmc2)) {
            throw new TestException(
                    "equals method should return true");
        }
       
        // 2
        bmc1 = new BasicMethodConstraints(constraints);
        bmc2 = new BasicMethodConstraints(constraints);
        if (!bmc1.equals(bmc2)) {
            throw new TestException(
                    "equals method should return true");
        }
       
        // 3
        MethodDesc [] simpleDescs = {methodDesc2};
        bmc1 = new BasicMethodConstraints(constraints);
        bmc2 = new BasicMethodConstraints(simpleDescs);
        if (!bmc1.equals(bmc2) || !bmc2.equals(bmc1)) {
            throw new TestException(
                    "equals method should return true");
        }
       
        // 4
        String name2 = "someDifferentMethod";
        MethodDesc methodDesc3 = new MethodDesc(name2, constraints);
        MethodDesc [] descs2 = {methodDesc3, methodDesc2};
        bmc1 = new BasicMethodConstraints(descs);
        bmc2 = new BasicMethodConstraints(descs2);
        if (bmc1.equals(bmc2)) {
            throw new TestException(
                    "equals method should return false");
        }
       
        // 5
        InvocationConstraint ic2 = Integrity.YES;
        InvocationConstraints constraints2 = new InvocationConstraints(
                ic2, null);
        bmc1 = new BasicMethodConstraints(constraints);
        bmc2 = new BasicMethodConstraints(constraints2);
        if (bmc1.equals(bmc2)) {
            throw new TestException(
                    "equals method should return false");
        }
       
        // 6
        bmc1 = new BasicMethodConstraints(constraints2);
        bmc2 = new BasicMethodConstraints(simpleDescs);
        if (bmc1.equals(bmc2) || bmc2.equals(bmc1)) {
            throw new TestException(
                    "equals method should return false");
        }
       
        // 7
        MethodDesc [] descs3 = {methodDesc3, methodDesc1};
        MethodDesc [] descs4 = {methodDesc1, methodDesc3};
        bmc1 = new BasicMethodConstraints(descs3);
        bmc2 = new BasicMethodConstraints(descs4);
        if (bmc1.equals(bmc2)) {
            throw new TestException(
                    "equals method should return false");
        }
    }
View Full Code Here

        InvocationConstraints constraints = new InvocationConstraints(
                ic, null);
        MethodDesc methodDesc1 = new MethodDesc(name, constraints);
        MethodDesc methodDesc2 = new MethodDesc(constraints);
        MethodDesc [] descs = {methodDesc1, methodDesc2};
        new BasicMethodConstraints(descs);

        // 2
        MethodDesc [] storedDescs = {methodDesc1, methodDesc2};
        MethodDesc [] passedDescs = {methodDesc1, methodDesc2};
        new BasicMethodConstraints(passedDescs);
        for (int j = 0; j < passedDescs.length; ++j) {
            if (storedDescs[j] != passedDescs[j]) {
                throw new TestException(
                        "MethodDesc array was modified");
            }
        }

        // 3
        String name2 = "*someMethod";
        MethodDesc methodDesc3 = new MethodDesc(name2, constraints);
        MethodDesc [] descs1 = {methodDesc1, methodDesc2};
        MethodDesc [] descs2 = {methodDesc1, methodDesc2};
        BasicMethodConstraints bmc1 = new BasicMethodConstraints(descs1);
        BasicMethodConstraints bmc2 = new BasicMethodConstraints(descs2);
        descs2[1] = methodDesc3;
        if (!bmc1.equals(bmc2)) {
            throw new TestException(
                    "BasicMethodConstraints objects should be equal");
        }

        // 4
        try {
            new BasicMethodConstraints((MethodDesc []) null);
            throw new TestException(
                    "NullPointerException should be thrown");
        } catch (NullPointerException ignore) {
        }

        // 5
        try {
            MethodDesc [] descs1null = {null, methodDesc2};
            new BasicMethodConstraints(descs1null);
            throw new TestException(
                    "NullPointerException should be thrown");
        } catch (NullPointerException ignore) {
        }
        try {
            MethodDesc [] descs2null = {methodDesc1, null};
            new BasicMethodConstraints(descs2null);
            throw new TestException(
                    "NullPointerException should be thrown");
        } catch (NullPointerException ignore) {
        }

        // 6
        try {
            MethodDesc [] emptyDescs = {};
            new BasicMethodConstraints(emptyDescs);
            throw new TestException(
                    "IllegalArgumentException should be thrown");
        } catch (IllegalArgumentException ignore) {
        }

        // 7
        try {
            MethodDesc [] invalidDescs = {methodDesc2, methodDesc1};
            new BasicMethodConstraints(invalidDescs);
            throw new TestException(
                    "IllegalArgumentException should be thrown");
        } catch (IllegalArgumentException ignore) {
        }

        // 8
        new BasicMethodConstraints(constraints);

        // 9
        InvocationConstraints emptyConstraints = new InvocationConstraints(
                (InvocationConstraint) null, null);
        bmc1 = new BasicMethodConstraints(emptyConstraints);
        bmc2 = new BasicMethodConstraints((InvocationConstraints) null);
        if (!bmc1.equals(bmc2)) {
            throw new TestException(
                    "BasicMethodConstraints objects should be equal");
        }

        // 10
        MethodDesc [] simpleDescs = {methodDesc2};
        bmc1 = new BasicMethodConstraints(constraints);
        bmc2 = new BasicMethodConstraints(simpleDescs);
        if (!bmc1.equals(bmc2)) {
            throw new TestException(
                    "BasicMethodConstraints objects should be equal");
        }
    }
View Full Code Here

        MethodDesc methodDesc3 = new MethodDesc(ics[3]);

        MethodDesc [] descs = {methodDesc0, methodDesc1, methodDesc2,
                methodDesc3};

        BasicMethodConstraints bmc = new BasicMethodConstraints(descs);

        m1:
        for (int j = 0; j < ics.length; ++j) {
            InvocationConstraints ic = ics[j];
            Iterator i = bmc.possibleConstraints();
            while (i.hasNext()) {
                if (((InvocationConstraints)(i.next())).equals(ic)) {
                    continue m1;
                }
            }
            throw new TestException(
                    "Iterator doesn't contain constraint: " + ic);
        }

        // 2
        bmc = new BasicMethodConstraints(ics[2]);
        try {
            Iterator i = bmc.possibleConstraints();
            while (i.hasNext()) {
                if (((InvocationConstraints)(i.next())).equals(ics[2])) {
                    throw new HaveFoundException();
                }
            }
            throw new TestException(
                    "Iterator doesn't contain constraint: " + ics[2]);
        } catch (HaveFoundException ignore) {
        }

        // 3
        bmc = new BasicMethodConstraints(descs);
        Iterator iterator = bmc.possibleConstraints();
        iterator.hasNext();
        try {
            iterator.remove();
        } catch (UnsupportedOperationException ignore) {
        }

        // 4
        bmc = new BasicMethodConstraints(ics[2]);
        iterator = bmc.possibleConstraints();
        iterator.hasNext();
        try {
            iterator.remove();
        } catch (UnsupportedOperationException ignore) {
        }
View Full Code Here

        InvocationConstraints constraints = new InvocationConstraints(
                ic, null);
        MethodDesc methodDesc1 = new MethodDesc(name, constraints);
        MethodDesc methodDesc2 = new MethodDesc(constraints);
        MethodDesc [] descs = {methodDesc1, methodDesc2};
        BasicMethodConstraints bmc1 = new BasicMethodConstraints(descs);
        bmc1.hashCode();
       
        // 2
        BasicMethodConstraints bmc2 = new BasicMethodConstraints(descs);
        if (bmc1.hashCode() != bmc2.hashCode()) {
            throw new TestException(
                    "hashCode for equal objects should be equal");
        }
       
        // 3
        bmc1 = new BasicMethodConstraints(constraints);
        bmc1.hashCode();
       
        // 4
        bmc2 = new BasicMethodConstraints(constraints);
        if (bmc1.hashCode() != bmc2.hashCode()) {
            throw new TestException(
                    "hashCode for equal objects should be equal");
        }

        // 5
        MethodDesc [] simpleDescs = {methodDesc2};
        bmc1 = new BasicMethodConstraints(constraints);
        bmc2 = new BasicMethodConstraints(simpleDescs);
        if (bmc1.hashCode() != bmc2.hashCode()) {
            throw new TestException(
                    "hashCode for equal objects should be equal");
        }
    }
View Full Code Here

        InvocationConstraints constraints = new InvocationConstraints(
                ic, null);
        MethodDesc methodDesc1 = new MethodDesc(name, constraints);
        MethodDesc methodDesc2 = new MethodDesc(constraints);
        MethodDesc [] descs = {methodDesc1, methodDesc2};
        BasicMethodConstraints bmc1 = new BasicMethodConstraints(descs);
        if (bmc1.toString().length() == 0) {
            throw new TestException(
                    "result should not be empty string");
        }
       
        // 2
        bmc1 = new BasicMethodConstraints(constraints);
        if (bmc1.toString().length() == 0) {
            throw new TestException(
                    "result should not be empty string");
        }
    }
View Full Code Here

        InvocationConstraint ic = Delegation.YES;
        InvocationConstraints constraints = new InvocationConstraints(
                ic, null);
        MethodDesc methodDesc = new MethodDesc(name, constraints);
        MethodDesc [] descs = {methodDesc};
        BasicMethodConstraints bmc = new BasicMethodConstraints(descs);
        Method mEquals = Object.class.getDeclaredMethod(name,
                new Class[] { Object.class });
        InvocationConstraints returnedConstraints =
                bmc.getConstraints(mEquals);
        if (!constraints.equals(returnedConstraints)) {
            throw new TestException(
                    "Invalid constraints was returned");
        }

        // 2
        String name1 = "hashCode";
        Method mHashCode = Object.class.getDeclaredMethod(name1,
                new Class[] {});
        returnedConstraints = bmc.getConstraints(mHashCode);
        InvocationConstraints emptyConstraints = new InvocationConstraints(
                (InvocationConstraint) null, null);
        if (!emptyConstraints.equals(returnedConstraints)) {
            throw new TestException(
                    "Empty constraints should be returned");
        }

        // 3
        String name2 = "*ashCode";
        InvocationConstraint ic2 = Delegation.NO;
        InvocationConstraints constraints2 = new InvocationConstraints(
                ic2, null);
        MethodDesc methodDesc2 = new MethodDesc(name2, constraints2);
        String name3 = "*shCode";
        InvocationConstraint ic3 = Integrity.NO;
        InvocationConstraints constraints3 = new InvocationConstraints(
                ic3, null);
        MethodDesc methodDesc3 = new MethodDesc(name3, constraints3);
        MethodDesc [] descs3 = {methodDesc, methodDesc2, methodDesc3};
        bmc = new BasicMethodConstraints(descs3);
        returnedConstraints = bmc.getConstraints(mHashCode);
        if (!returnedConstraints.equals(constraints2)) {
            throw new TestException(
                    "Invalid constraints was returned:"
                    + returnedConstraints
                    + ", should be:" + constraints2);
        }

        // 4
        MethodDesc methodDesc1 = new MethodDesc(name,
                new Class[] {}, constraints2);
        methodDesc2 = new MethodDesc(name,
                new Class[] { Object.class, Class.class }, constraints2);
        methodDesc3 = new MethodDesc(name,
                new Class[] { Object.class }, constraints3);
        MethodDesc [] descs4 = {methodDesc1, methodDesc2, methodDesc3};
        bmc = new BasicMethodConstraints(descs4);
        returnedConstraints = bmc.getConstraints(mEquals);
        if (!returnedConstraints.equals(constraints3)) {
            throw new TestException(
                    "Invalid constraints was returned:"
                    + returnedConstraints
                    + ", should be:" + constraints2);
        }

        // 5
        try {
            bmc.getConstraints(null);
            throw new TestException(
                    "NullPointerException should be thrown");
        } catch (NullPointerException ignore) {
        }
    }
View Full Code Here

TOP

Related Classes of net.jini.constraint.BasicMethodConstraints

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.