Esempio n. 1
0
  @Test
  public void test410TestResource() throws Exception {
    final String TEST_NAME = "test410TestResource";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(TEST_DUMMY_RESOURCE_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    IntegrationTestTools.display("output", output.getFinalOutput());
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    ResourceType dummy =
        modelService
            .getObject(
                ResourceType.class,
                RESOURCE_DUMMY_OID,
                null,
                taskManager.createTaskInstance(),
                result)
            .asObjectable();
    IntegrationTestTools.display("dummy resource after test connection", dummy.asPrismObject());
    IntegrationTestTools.display(result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(1, output.getFinalOutput().getData().size());
    assertEquals(
        "Tested resource:10000000-0000-0000-0000-000000000004(Dummy Resource): SUCCESS\n",
        output.getConsoleOutput());
  }
Esempio n. 2
0
  public boolean evaluateConfirmationExpression(
      UserType user,
      ShadowType shadow,
      ExpressionType expressionType,
      Task task,
      OperationResult result)
      throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    Validate.notNull(user, "User must not be null.");
    Validate.notNull(shadow, "Resource object shadow must not be null.");
    Validate.notNull(expressionType, "Expression must not be null.");
    Validate.notNull(result, "Operation result must not be null.");

    ResourceType resource = resolveResource(shadow, result);
    ExpressionVariables variables = getDefaultXPathVariables(user, shadow, resource);
    String shortDesc = "confirmation expression for " + resource.asPrismObject();

    PrismPropertyDefinition<Boolean> outputDefinition =
        new PrismPropertyDefinition<>(
            ExpressionConstants.OUTPUT_ELMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression =
        expressionFactory.makeExpression(expressionType, outputDefinition, shortDesc, task, result);

    ExpressionEvaluationContext params =
        new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple =
        ModelExpressionThreadLocalHolder.evaluateExpressionInContext(
            expression, params, task, result);
    Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues();
    if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
      throw new ExpressionEvaluationException(
          "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
    }
    if (nonNegativeValues.size() > 1) {
      throw new ExpressionEvaluationException(
          "Expression returned more than one value ("
              + nonNegativeValues.size()
              + ") in "
              + shortDesc);
    }
    PrismPropertyValue<Boolean> resultpval = nonNegativeValues.iterator().next();
    if (resultpval == null) {
      throw new ExpressionEvaluationException(
          "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
    }
    Boolean resultVal = resultpval.getValue();
    if (resultVal == null) {
      throw new ExpressionEvaluationException(
          "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
    }
    return resultVal;
  }
  /**
   * Simple call to connector test() method.
   *
   * @throws Exception
   */
  @Test
  public void test310TestConnectionNegative() throws Exception {
    final String TEST_NAME = "test310TestConnectionNegative";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN

    OperationResult result = new OperationResult(TEST_NAME);

    ConnectorInstance badConnector =
        factory.createConnectorInstance(
            connectorType,
            ResourceTypeUtil.getResourceNamespace(badResourceType),
            "test connector");
    badConnector.configure(
        badResourceType.getConnectorConfiguration().asPrismContainerValue(), result);

    // WHEN

    badConnector.test(result);

    // THEN
    result.computeStatus("test failed");
    display("Test result (FAILURE EXPECTED)", result);
    AssertJUnit.assertNotNull(result);
    OperationResult connectorConnectionResult = result.getSubresults().get(1);
    AssertJUnit.assertNotNull(connectorConnectionResult);
    System.out.println(
        "Test \"connector connection\" result: "
            + connectorConnectionResult
            + " (FAILURE EXPECTED)");
    AssertJUnit.assertTrue(
        "Unexpected success of bad connector test", !connectorConnectionResult.isSuccess());
    AssertJUnit.assertTrue(!result.isSuccess());
  }
 public static void setParsedResourceSchemaConditional(
     ResourceType resourceType, ResourceSchema parsedSchema) {
   if (hasParsedSchema(resourceType)) {
     return;
   }
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   resource.setUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA, parsedSchema);
 }
Esempio n. 5
0
  @Test
  public void test020AddResourceOpenDj() throws Exception {
    final String TEST_NAME = "test020AddResourceOpenDj";
    displayTestTitle(TEST_NAME);

    LogfileTestTailer tailer = createLogTailer();
    ResourceType resource = ModelClientUtil.unmarshallFile(RESOURCE_OPENDJ_FILE);

    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setObjectType(getTypeQName(ResourceType.class));
    delta.setChangeType(ChangeTypeType.ADD);
    delta.setObjectToAdd(resource);
    deltaList.getDelta().add(delta);

    ModelExecuteOptionsType options = new ModelExecuteOptionsType();
    options.setIsImport(Boolean.TRUE);

    XMLGregorianCalendar startTs = TestUtil.currentTime();

    // WHEN
    ObjectDeltaOperationListType deltaOpList = modelPort.executeChanges(deltaList, options);

    // THEN
    assertSuccess(deltaOpList);
    String oid = deltaOpList.getDeltaOperation().get(0).getObjectDelta().getOid();

    XMLGregorianCalendar endTs = TestUtil.currentTime();

    tailer.tail();
    displayAudit(tailer);
    assertAuditLoginLogout(tailer);
    assertAuditIds(tailer);
    assertAuditOperation(tailer, "ADD_OBJECT");
    tailer.assertAudit(4);

    assertEquals("Wrong OID", RESOURCE_OPENDJ_OID, oid);

    ResourceType resourceAfter = getObject(ResourceType.class, RESOURCE_OPENDJ_OID);
    display(resourceAfter);

    assertEquals("Wrong connector OID", connectorLdapOid, resourceAfter.getConnectorRef().getOid());

    assertCreateMetadata(resourceAfter, USER_ADMINISTRATOR_OID, startTs, endTs);
  }
Esempio n. 6
0
  public static ExpressionVariables getDefaultXPathVariables(
      UserType user, ShadowType shadow, ResourceType resource) {

    ExpressionVariables variables = new ExpressionVariables();
    if (user != null) {
      variables.addVariableDefinition(ExpressionConstants.VAR_USER, user.asPrismObject());
    }

    if (shadow != null) {
      variables.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadow.asPrismObject());
    }

    if (resource != null) {
      variables.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource.asPrismObject());
    }

    return variables;
  }
  @BeforeMethod
  public void initUcf() throws Exception {
    TestUtil.displayTestTile("initUcf");

    File file = new File(FILENAME_RESOURCE_OPENDJ);
    FileInputStream fis = new FileInputStream(file);

    // Resource
    PrismObject<ResourceType> resource =
        PrismTestUtil.parseObject(new File(FILENAME_RESOURCE_OPENDJ));
    resourceType = resource.asObjectable();

    // Resource: Second copy for negative test cases
    PrismObject<ResourceType> badResource =
        PrismTestUtil.parseObject(new File(FILENAME_RESOURCE_OPENDJ_BAD));
    badResourceType = badResource.asObjectable();

    // Connector
    PrismObject<ConnectorType> connector =
        PrismTestUtil.parseObject(new File(FILENAME_CONNECTOR_LDAP));
    connectorType = connector.asObjectable();

    factory = connectorFactoryIcfImpl;

    cc =
        factory.createConnectorInstance(
            connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector");
    AssertJUnit.assertNotNull("Cannot create connector instance", cc);

    connectorSchema = cc.generateConnectorSchema();
    AssertJUnit.assertNotNull("Cannot generate connector schema", cc);
    display("Connector schema", connectorSchema);

    OperationResult result = new OperationResult("initUcf");
    cc.configure(resourceType.getConnectorConfiguration().asPrismContainerValue(), result);
    cc.initialize(null, null, false, result);
    // TODO: assert something

    resourceSchema = cc.fetchResourceSchema(null, result);
    display("Resource schema", resourceSchema);

    AssertJUnit.assertNotNull(resourceSchema);
  }
  public static RefinedResourceSchema parse(ResourceType resourceType, PrismContext prismContext)
      throws SchemaException {

    ResourceSchema originalResourceSchema = getResourceSchema(resourceType, prismContext);
    if (originalResourceSchema == null) {
      return null;
    }

    String contextDescription = "definition of " + resourceType;

    RefinedResourceSchemaImpl rSchema = new RefinedResourceSchemaImpl(originalResourceSchema);

    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (schemaHandling != null) {
      parseObjectTypeDefsFromSchemaHandling(
          rSchema,
          resourceType,
          schemaHandling,
          schemaHandling.getObjectType(),
          null,
          prismContext,
          contextDescription);
    }

    parseObjectTypesFromSchema(rSchema, resourceType, prismContext, contextDescription);

    // We need to parse associations and auxiliary object classes in a second pass. We need to have
    // all object classes parsed before correctly setting association
    // targets
    for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) {
      ((RefinedObjectClassDefinitionImpl) rOcDef).parseAssociations(rSchema);
      ((RefinedObjectClassDefinitionImpl) rOcDef).parseAuxiliaryObjectClasses(rSchema);
    }

    // We can parse attributes only after we have all the object class info parsed (including
    // auxiliary object classes)
    for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) {
      ((RefinedObjectClassDefinitionImpl) rOcDef).parseAttributes(rSchema, contextDescription);
    }

    return rSchema;
  }
 public static boolean hasParsedSchema(ResourceType resourceType) {
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   return resource.getUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA) != null;
 }
 public static ResourceSchema getResourceSchema(
     ResourceType resourceType, PrismContext prismContext) throws SchemaException {
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   return getResourceSchema(resource, prismContext);
 }
 public static boolean hasRefinedSchema(ResourceType resourceType) {
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   return resource.getUserData(USER_DATA_KEY_REFINED_SCHEMA) != null;
 }
 public static LayerRefinedResourceSchema getRefinedSchema(
     ResourceType resourceType, LayerType layer, PrismContext prismContext)
     throws SchemaException {
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   return getRefinedSchema(resource, layer, prismContext);
 }
 public static LayerRefinedResourceSchema getRefinedSchema(
     ResourceType resourceType, LayerType layer) throws SchemaException {
   return getRefinedSchema(resourceType, layer, resourceType.asPrismObject().getPrismContext());
 }