use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.
the class ResourceTest method save.
@Test
public void save() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-save");
// specify the connector
ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
resource.setConnector(connector);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
// specify mappings
for (int i = 0; i < 3; i++) {
MappingItem item = entityFactory.newEntity(MappingItem.class);
item.setExtAttrName("test" + i);
item.setIntAttrName("nonexistent" + i);
item.setMandatoryCondition("false");
item.setPurpose(MappingPurpose.PULL);
mapping.add(item);
item.setMapping(mapping);
}
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setExtAttrName("username");
connObjectKey.setIntAttrName("username");
connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(connObjectKey);
connObjectKey.setMapping(mapping);
// map a derived attribute
MappingItem derived = entityFactory.newEntity(MappingItem.class);
derived.setConnObjectKey(false);
derived.setExtAttrName("fullname");
derived.setIntAttrName("cn");
derived.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(derived);
derived.setMapping(mapping);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
resourceDAO.flush();
resourceDAO.detach(actual);
connInstanceDAO.detach(connector);
// assign the new resource to an user
User user = userDAO.findByUsername("rossini");
assertNotNull(user);
user.add(actual);
resourceDAO.flush();
// retrieve resource
resource = resourceDAO.find(actual.getKey());
assertNotNull(resource);
resourceDAO.refresh(resource);
// check connector
connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
assertNotNull(connector.getResources());
assertNotNull(resource.getConnector());
assertTrue(resource.getConnector().equals(connector));
// check mappings
List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
assertNotNull(items);
assertEquals(5, items.size());
// check user
user = userDAO.findByUsername("rossini");
assertNotNull(user);
assertNotNull(user.getResources());
assertTrue(user.getResources().contains(actual));
}
use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.
the class ResourceTest method findById.
@Test
public void findById() {
ExternalResource resource = resourceDAO.find("ws-target-resource-1");
assertNotNull(resource);
ConnInstance connector = resource.getConnector();
assertNotNull(connector);
assertEquals("net.tirasa.connid.bundles.soap.WebServiceConnector", connector.getConnectorName());
assertEquals("net.tirasa.connid.bundles.soap", connector.getBundleName());
Mapping mapping = resource.getProvision(anyTypeDAO.findUser()).get().getMapping();
assertFalse(mapping.getItems().isEmpty());
assertTrue(mapping.getItems().stream().anyMatch(item -> "7f55b09c-b573-41dc-a9eb-ccd80bd3ea7a".equals(item.getKey())));
try {
resourceDAO.authFind("ws-target-resource-1");
fail("This should not happen");
} catch (DelegatedAdministrationException e) {
assertNotNull(e);
}
}
use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.
the class ResourceTest method save.
@Test
public void save() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-basic-save");
resource.setPropagationPriority(2);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setExtAttrName("username");
connObjectKey.setIntAttrName("fullname");
connObjectKey.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(connObjectKey);
ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
resource.setConnector(connector);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertNotNull(actual.getConnector());
assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
assertFalse(actual.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().isEmpty());
assertEquals(Integer.valueOf(2), actual.getPropagationPriority());
}
use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.
the class ResourceTest method saveInvalidMappingIntAttr.
@Test
public void saveInvalidMappingIntAttr() {
assertThrows(InvalidEntityException.class, () -> {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-basic-save-invalid");
ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
resource.setConnector(connector);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setConnObjectKey(true);
mapping.add(connObjectKey);
// save the resource
resourceDAO.save(resource);
});
}
use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.
the class ResourceTest method saveWithGroupMappingType.
@Test
public void saveWithGroupMappingType() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-basic-save-invalid");
ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
resource.setConnector(connector);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
MappingItem item = entityFactory.newEntity(MappingItem.class);
item.setIntAttrName("fullname");
item.setExtAttrName("fullname");
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
item = entityFactory.newEntity(MappingItem.class);
item.setIntAttrName("icon");
item.setExtAttrName("icon");
item.setPurpose(MappingPurpose.BOTH);
mapping.add(item);
item = entityFactory.newEntity(MappingItem.class);
item.setIntAttrName("mderiveddata");
item.setExtAttrName("mderiveddata");
item.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(item);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertEquals(3, actual.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
}
Aggregations