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);
            callConstructor(testCase, name, types, constraints);
           
            // 2
            if (testCase == case2arg) {
                name = "*someMethod";
                callConstructor(testCase, name, types, constraints);

                name = "*5someMethod";
                callConstructor(testCase, name, types, constraints);
            }
           
            // 3
            if (testCase == case2arg) {
                name = "someMethod*";
                callConstructor(testCase, name, types, constraints);
            }
           
            // 4
            if (testCase == case3arg) {
                name = "someMethod";
                Class[] storedTypes = new Class[types.length];
                for (int j = 0; j < types.length; ++j) {
                    storedTypes[j] = types[j];
                }
                callConstructor(testCase, name, types, constraints);
                if (storedTypes.length != types.length) {
                    throw new TestException(
                            "types array length was modified");
                }
                for (int j = 0; j < types.length; ++j) {
                    if (storedTypes[j] != types[j]) {
                        throw new TestException(
                                "types array was modified");
                    }
                }
               
            }
           
            // 5
            if (testCase == case3arg) {
                name = "someMethod";
                Class[] types2 = new Class[types.length];
                for (int j = 0; j < types.length; ++j) {
                    types2[j] = types[j];
                }
                MethodDesc md1 =
                    callConstructor(testCase, name, types, constraints);
                MethodDesc md2 =
                    callConstructor(testCase, name, types2, constraints);
                if (!md1.equals(md2)) {
                    throw new TestException(
                            "MethodDesc objects should be equal");
                }
                types2[0] = long.class;
                if (!md1.equals(md2)) {
                    throw new TestException(
                            "MethodDesc objects should be equal");
                }
            }
           
            // 6
            name = "someMethod";
            InvocationConstraints emptyConstraints = new InvocationConstraints(
                    (InvocationConstraint) null, null);
            MethodDesc md1 =
                callConstructor(testCase, name, types, emptyConstraints);
            MethodDesc md2 =
                callConstructor(testCase, name, types, null);
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

  throws UnsupportedConstraintException
    {
  if (constraints == null)
      throw new NullPointerException();

  InvocationConstraints unfulfilledConstraints;
  try {
      // check for unsupportable constraints
      for (Iterator iter = constraints.requirements().iterator();
     iter.hasNext(); )
      {
View Full Code Here

        throw uce;
    }
      }
     
      // constraints need upper layer help to be fully fulfilled
      InvocationConstraints unfulfilledConstraints =
    InvocationConstraints.EMPTY;

      if (KerberosUtil.containsConstraint(
    constraints.requirements(), Integrity.YES))
      {
View Full Code Here

  {
      check(requestHandle);
      if (constraints == null) {
    throw new NullPointerException("Constraints cannot be null");
      }
      InvocationConstraints result = getUnfulfilledConstraints(
    cipherSuite, clientPrincipal, serverPrincipal, constraints);
      if (result == null) {
    UnsupportedConstraintException uce =
        new UnsupportedConstraintException(
      "Constraints are not supported: " + constraints);
View Full Code Here

   * If there are relative constraints, create new method constraints
   * to set on the underlying proxy before invoking a method.
   */
  MethodConstraints convertedConstraints = null;
  if (clientConstraints != null) {
      InvocationConstraints relativeConstraints =
    clientConstraints.getConstraints(method);
      InvocationConstraints absoluteConstraints =
    relativeConstraints.makeAbsolute();
      if (relativeConstraints != absoluteConstraints) {
    convertedConstraints =
        new BasicMethodConstraints(absoluteConstraints);
      }
View Full Code Here

    }

    private DiscoveryConstraints(InvocationConstraints constraints)
  throws UnsupportedConstraintException
    {
  unfulfilled = new InvocationConstraints(
      getUnfulfilled(constraints.requirements()),
      getUnfulfilled(constraints.preferences()));

  ConstraintReducer cr =
      new ConstraintReducer(DiscoveryProtocolVersion.class);
  protocolVersions = cr.reduce(
      new InvocationConstraints(constraints.requirements(), null));
  if (!protocolVersions.isEmpty() &&
      intersect(protocolVersions, supportedProtocols).isEmpty())
  {
      throw new UnsupportedConstraintException(
    "no supported protocols: " + protocolVersions);
  }
  preferredProtocolVersion = chooseProtocolVersion(
      protocolVersions, cr.reduce(constraints), unfulfilled);

  Set s = new MulticastMaxPacketSizeReducer().reduce(constraints);
  maxPacketSize = s.isEmpty() ?
      null : (MulticastMaxPacketSize) getElement(s);

  s = new ConstraintReducer(
      MulticastTimeToLive.class).reduce(constraints);
  timeToLive = s.isEmpty() ? null : (MulticastTimeToLive) getElement(s);

  s = new ConstraintReducer(
      UnicastSocketTimeout.class).reduce(constraints);
  socketTimeout = s.isEmpty() ?
      null : (UnicastSocketTimeout) getElement(s);
 
  InvocationConstraints absConstraints =
      new InvocationConstraints(
    constraints.requirements(),
    constraints.preferences()).makeAbsolute();
  s = new ConnectionAbsoluteTimeReducer().reduce(absConstraints);
 
  connectionAbsoluteTime = s.isEmpty() ?
View Full Code Here

      client = (Principal) cIter.next();
      assert client != null;
        } else {
      client = null;
        }
        InvocationConstraints unfulfilledConstraints =
      getUnfulfilledConstraints(
          suite, client, server, constraints);
        if (unfulfilledConstraints != null) {
      if (logger.isLoggable(Level.FINE)) {
          logger.log(Level.FINE,
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.