Package com.google.enterprise.connector.mock

Examples of com.google.enterprise.connector.mock.MockRepositoryProperty


      throw new IllegalArgumentException("test input can not be parsed");
    }
    MockRepositoryPropertyList pl = new MockRepositoryPropertyList(jo);

    {
      MockRepositoryProperty testProp = pl.getProperty("xyzzy");
      Property testJCRProp = new MockJcrProperty(testProp);
      Assert.assertEquals("skeedle", testJCRProp.getString());
      Assert.assertEquals(PropertyType.STRING, testJCRProp.getType());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("baz");
      Property testJCRProp = new MockJcrProperty(testProp);
      Assert.assertEquals(42, testJCRProp.getLong());
      Assert.assertEquals(PropertyType.LONG, testJCRProp.getType());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("abc");
      Property testJCRProp = new MockJcrProperty(testProp);
      try {
        testJCRProp.getLong();
        // shouldn't get here - previous line should throw exception
        Assert.assertFalse(true);
      } catch (Exception e) {
        // Specifically, ValueFormatException should be thrown
        Assert.assertTrue(e instanceof ValueFormatException);
      }
      Value[] vs = testJCRProp.getValues();
      Assert.assertEquals(PropertyType.LONG, testJCRProp.getType());
      Assert.assertEquals(5, vs.length);
      Assert.assertEquals(2, vs[0].getLong());
      Assert.assertEquals(3, vs[1].getLong());
      Assert.assertEquals(5, vs[2].getLong());
      Assert.assertEquals(7, vs[3].getLong());
      Assert.assertEquals(11, vs[4].getLong());
      Assert.assertEquals(PropertyType.LONG, vs[4].getType());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("def");
      Property testJCRProp = new MockJcrProperty(testProp);
      Value[] vs = testJCRProp.getValues();
      Assert.assertEquals(PropertyType.DATE, testJCRProp.getType());
      Assert.assertEquals(3, vs.length);
      Calendar date = vs[0].getDate();
      Calendar expected = Calendar.getInstance();
      expected.setTimeInMillis(10 * 1000);
      Assert.assertTrue(date.equals(expected));
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("ghi");
      Property testJCRProp = new MockJcrProperty(testProp);
      Value[] vs = testJCRProp.getValues();
      Assert.assertEquals(PropertyType.LONG, testJCRProp.getType());
      Assert.assertEquals(0, vs.length);
    }
View Full Code Here


   * or throws a suitable <code>java.security.AccessControlException</code>
   * otherwise.
   */
  private void checkPermission(String userId, MockRepositoryDocument doc)
      throws AccessControlException {
    MockRepositoryProperty property = doc.getProplist().getProperty("acl");
    if (property == null) {
      return;
    }
    String[] values = property.getValues();
    for (int i = 0; i < values.length; i++) {
      String aclEntry = values[i];
      // Extract the scope type and compare.
      int scopeTokPos = aclEntry.indexOf(MockRepositoryProperty.SCOPE_TYPE_SEP);
      if (scopeTokPos != -1) {
View Full Code Here

  }

  private void init() {
    propList = new LinkedList<MockJcrProperty>();
    // Convert the special MockRepositoryDocument schema to a JCR property list
    MockRepositoryProperty p = null;
    // content
    try {
      p = new MockRepositoryProperty("jcr:content", doc.getContentStream());
    } catch (FileNotFoundException e) {
      LOGGER.severe(e.toString());
    }
    if (p != null) {
      propList.add(new MockJcrProperty(p));
    }
    // modified date
    p = new MockRepositoryProperty("jcr:lastModified",
        MockRepositoryProperty.PropertyType.DATE, Integer.toString(doc
            .getTimeStamp().getTicks()));
    propList.add(new MockJcrProperty(p));
    // docid
    p = new MockRepositoryProperty("jcr:uuid", doc.getDocID());
    propList.add(new MockJcrProperty(p));
    // acl
    MockRepositoryProperty aclProp = doc.getProplist().getProperty("acl");
    if (aclProp != null) {
      addAclProperty(MockRepositoryProperty.USER_SCOPE, aclProp, propList,
          SpiConstants.PROPNAME_ACLUSERS,
          SpiConstants.USER_ROLES_PROPNAME_PREFIX);
      addAclProperty(MockRepositoryProperty.GROUP_SCOPE, aclProp, propList,
          SpiConstants.PROPNAME_ACLGROUPS,
          SpiConstants.GROUP_ROLES_PROPNAME_PREFIX);
    }
    // acldeny
    MockRepositoryProperty aclDenyProp =
        doc.getProplist().getProperty("acldeny");
    if (aclDenyProp != null) {
      addAclProperty(MockRepositoryProperty.USER_SCOPE, aclDenyProp, propList,
          SpiConstants.PROPNAME_ACLDENYUSERS, null);
      addAclProperty(MockRepositoryProperty.GROUP_SCOPE, aclDenyProp, propList,
View Full Code Here

        // the propList.
        newAclScopes.add("\"" + scopeId + "\"");
        if (rolesStr != null) {
          // Create a multi-value property for the scope's roles.
          List<String> rolesList = Arrays.asList(rolesStr.split(",", 0));
          MockRepositoryProperty newRolesProp = new MockRepositoryProperty(
              rolesPrefix + scopeId,
              "{type:string, value:" + rolesList.toString() + "}");
          propList.add(new MockJcrProperty(newRolesProp));
        }
      }
    }

    if (newAclScopes.size() > 0) {
      MockRepositoryProperty newAclProp = new MockRepositoryProperty(propName,
          "{type:string, value:" + newAclScopes.toString() + "}");
      propList.add(new MockJcrProperty(newAclProp));
    }
  }
View Full Code Here

      throw new IllegalArgumentException("test input can not be parsed");
    }
    MockRepositoryPropertyList pl = new MockRepositoryPropertyList(jo);

    {
      MockRepositoryProperty testProp = pl.getProperty("xyzzy");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      Value v = p.nextValue();
      Assert.assertEquals("skeedle", v.toString());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("baz");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      Value v = p.nextValue();
      Assert.assertEquals("42", v.toString());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("abc");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      int counter = 0;
      Value v = null;
      while ((v = p.nextValue()) != null) {
        String res = v.toString();
        switch (counter) {
        case 0:
          Assert.assertEquals("2", res);
          break;
        case 1:
          Assert.assertEquals("3", res);
          break;
        case 2:
          Assert.assertEquals("5", res);
          break;
        case 3:
          Assert.assertEquals("7", res);
          break;
        case 4:
          Assert.assertEquals("11", res);
          break;
        }
        counter++;
      }
      Assert.assertEquals(5, counter);
    }

    {
      // TODO: date test
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("ghi");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      Value v = p.nextValue();
      Assert.assertNull(v);
    }
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.mock.MockRepositoryProperty

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.