@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);
  }
  @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);
  }
  @Test
  public void testProcessDataRelationTypeMatchBothMatch() 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.BOTH);

    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);

    MockArtifactProxy artData =
        new MockArtifactProxy(
            GUID.create(), artArtType, null, null, Collections.singleton(testRelationType));
    RelationTypeSide expectedObject1 = new RelationTypeSide(testRelationType, RelationSide.SIDE_A);
    RelationTypeSide expectedObject2 = new RelationTypeSide(testRelationType, RelationSide.SIDE_B);

    final List<AccessDetail<?>> actualAccesses = new ArrayList<>();
    AccessDetailCollector collector =
        new AccessDetailCollector() {

          @Override
          public void collect(AccessDetail<?> accessDetail) {
            Assert.assertNotNull(accessDetail);
            actualAccesses.add(accessDetail);
          }
        };

    Scope expectedScope = new Scope();
    getRestrictionHandler().process(restriction, artData, collector, expectedScope);

    AccessDetail<?> actualAccess = actualAccesses.get(0);
    Assert.assertEquals(actualAccess.getPermission(), PermissionEnum.WRITE);
    Assert.assertEquals(expectedObject1, actualAccess.getAccessObject());

    actualAccess = actualAccesses.get(1);
    Assert.assertEquals(actualAccess.getPermission(), PermissionEnum.WRITE);
    Assert.assertEquals(expectedObject2, actualAccess.getAccessObject());
  }
  @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);
  }
  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);
  }
 public RelationTypeRestrictionHandlerTest() {
   super(
       new RelationTypeRestrictionHandler(new ArtifactMatchInterpreter()),
       MockModel.createRelationTypeRestriction(),
       MockModel.createAttributeTypeRestriction());
 }