コード例 #1
0
  @Test
  public void testProcessDataRelationTypeMatchSideANoMatch() throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);
    restriction.setRestrictedToSide(XRelationSideEnum.SIDE_A);

    RelationType testRelationType =
        getTestRelationType(
            relationType, CoreArtifactTypes.Artifact, CoreArtifactTypes.SoftwareRequirement);

    IArtifactType artTypeToken1 = CoreArtifactTypes.SoftwareRequirement;
    ArtifactType artArtType =
        new ArtifactType(artTypeToken1.getGuid(), artTypeToken1.getName(), false);

    MockArtifactProxy artData =
        new MockArtifactProxy(
            GUID.create(), artArtType, null, null, Collections.singleton(testRelationType));
    RelationTypeSide expectedObject = new RelationTypeSide(testRelationType, RelationSide.SIDE_A);
    Scope expectedScope = new Scope();
    DslAsserts.assertAccessDetail(
        getRestrictionHandler(),
        restriction,
        artData,
        expectedObject,
        PermissionEnum.WRITE,
        expectedScope);
  }
コード例 #2
0
  @Test
  public void testProcessDataArtifactTypeMatch() throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;

    IArtifactType artifactType = CoreArtifactTypes.AbstractSoftwareRequirement;
    XArtifactType artifactTypeRef =
        MockModel.createXArtifactType(artifactType.getGuid(), artifactType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeMatch(true);

    RelationTypeArtifactTypePredicate predicate =
        OseeDslFactory.eINSTANCE.createRelationTypeArtifactTypePredicate();
    predicate.setArtifactTypeRef(artifactTypeRef);

    restriction.setPredicate(predicate);
    restriction.setRestrictedToSide(XRelationSideEnum.SIDE_B);

    RelationType testRelationType =
        getTestRelationType(
            relationType, CoreArtifactTypes.SoftwareRequirement, CoreArtifactTypes.Artifact);

    IArtifactType artTypeToken1 = CoreArtifactTypes.SoftwareRequirement;
    ArtifactType artArtType =
        new ArtifactType(artTypeToken1.getGuid(), artTypeToken1.getName(), false);
    Set<ArtifactType> superTypes = new HashSet<>();
    superTypes.add(
        new ArtifactType(
            CoreArtifactTypes.AbstractSoftwareRequirement.getGuid(),
            CoreArtifactTypes.AbstractSoftwareRequirement.getName(),
            false));
    artArtType.setSuperTypes(superTypes);

    DefaultBasicArtifact expectedAccessObject =
        new DefaultBasicArtifact(1, GUID.create(), "Another Artifact");
    MockArtifactProxy artData =
        new MockArtifactProxy(
            expectedAccessObject.getGuid(),
            artArtType,
            expectedAccessObject,
            null,
            Collections.singleton(testRelationType));

    RelationTypeSide expectedObject = new RelationTypeSide(testRelationType, RelationSide.SIDE_B);

    Scope expectedScope = new Scope();
    expectedScope.addSubPath(artData.getName());
    DslAsserts.assertAccessDetail(
        getRestrictionHandler(),
        restriction,
        artData,
        expectedObject,
        PermissionEnum.WRITE,
        expectedScope);
  }
コード例 #3
0
  @Test
  public void testProcessDataRelationTypeNoMatch() throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);

    // Artifact Data has no relation types therefore relation type will not match
    MockArtifactProxy artData = new MockArtifactProxy(GUID.create(), null);
    Scope expectedScope = new Scope().add("fail");
    DslAsserts.assertNullAccessDetail(getRestrictionHandler(), restriction, artData, expectedScope);
  }
コード例 #4
0
  private void testProcessRelationWithArtifactHelper(
      String artifactName, String matcherArtifactName, Scope expectedScope)
      throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);
    restriction.setRestrictedToSide(XRelationSideEnum.SIDE_B);

    XArtifactMatcher matcher =
        MockModel.createMatcher(
            "artifactMatcher \"Test\" where artifactName EQ \"" + matcherArtifactName + "\";");

    RelationTypeArtifactPredicate predicate =
        OseeDslFactory.eINSTANCE.createRelationTypeArtifactPredicate();
    predicate.setArtifactMatcherRef(matcher);
    restriction.setPredicate(predicate);

    RelationType testRelationType =
        getTestRelationType(
            relationType, CoreArtifactTypes.SoftwareRequirement, CoreArtifactTypes.Artifact);

    IArtifactType artTypeToken1 = CoreArtifactTypes.SoftwareRequirement;
    ArtifactType artArtType =
        new ArtifactType(artTypeToken1.getGuid(), artTypeToken1.getName(), false);
    Set<ArtifactType> superTypes = new HashSet<>();
    superTypes.add(
        new ArtifactType(
            CoreArtifactTypes.Artifact.getGuid(), CoreArtifactTypes.Artifact.getName(), false));
    artArtType.setSuperTypes(superTypes);

    IBasicArtifact<Object> dummy = new DefaultBasicArtifact(43, GUID.create(), artifactName);
    MockArtifactProxy artData =
        new MockArtifactProxy(
            GUID.create(), artArtType, dummy, null, Collections.singleton(testRelationType));
    RelationTypeSide expectedObject = new RelationTypeSide(testRelationType, RelationSide.SIDE_B);
    DslAsserts.assertAccessDetail(
        getRestrictionHandler(),
        restriction,
        artData,
        expectedObject,
        PermissionEnum.WRITE,
        expectedScope);
  }