Source:
public void testSaveOneSidedRelationshipField_returns_newRelationshipObject() throws DotSecurityException, DotDataException { final long time = System.currentTimeMillis(); ContentType parentContentType = null; ContentType childContentType = null; try { parentContentType = ContentTypeBuilder.builder(SimpleContentType.class).folder( FolderAPI.SYSTEM_FOLDER).host(Host.SYSTEM_HOST).name("parentContentType" + time) .owner(user.getUserId()).build(); parentContentType = contentTypeAPI.save(parentContentType); childContentType = ContentTypeBuilder.builder(SimpleContentType.class).folder( FolderAPI.SYSTEM_FOLDER).host(Host.SYSTEM_HOST).name("childContentType" + time) .owner(user.getUserId()).build(); childContentType = contentTypeAPI.save(childContentType); Field field = FieldBuilder.builder(RelationshipField.class).name("newRel") .contentTypeId(parentContentType.id()).values("1") .relationType(childContentType.variable()).build(); field = fieldAPI.save(field, user); final String fullFieldVar = parentContentType.variable() + StringPool.PERIOD + field.variable(); final Relationship relationship = relationshipAPI.byTypeValue(fullFieldVar); assertNotNull(relationship); assertNull(relationship.getParentRelationName()); assertEquals(parentContentType.id(), relationship.getParentStructureInode()); assertEquals(childContentType.id(), relationship.getChildStructureInode()); assertEquals(field.variable(), relationship.getChildRelationName()); assertEquals(1, relationship.getCardinality()); assertEquals(fullFieldVar, relationship.getRelationTypeValue()); } finally { if (UtilMethods.isSet(parentContentType) && UtilMethods.isSet(parentContentType.id())) { contentTypeAPI.delete(parentContentType); } if (UtilMethods.isSet(childContentType) && UtilMethods.isSet(childContentType.id())) { contentTypeAPI.delete(childContentType); } } }

Target:
public void testSaveOneSidedRelationshipField_returns_newRelationshipObject() throws DotSecurityException, DotDataException { final long time = System.currentTimeMillis(); ContentType parentContentType = null; ContentType childContentType = null; try { parentContentType = createAndSaveSimpleContentType("parentContentType" + time); childContentType = createAndSaveSimpleContentType("childContentType" + time); final Field parentTypeRelationshipField = createAndSaveManyToManyRelationshipField("newRel", parentContentType.id(), childContentType.variable(), CARDINALITY); final String fullFieldVar = parentContentType.variable() + StringPool.PERIOD + parentTypeRelationshipField.variable(); final Relationship relationship = relationshipAPI.byTypeValue(fullFieldVar); assertNotNull(relationship); assertNull(relationship.getParentRelationName()); assertEquals(parentContentType.id(), relationship.getParentStructureInode()); assertEquals(childContentType.id(), relationship.getChildStructureInode()); assertEquals(parentTypeRelationshipField.variable(), relationship.getChildRelationName()); assertEquals(CARDINALITY, Integer.toString(relationship.getCardinality())); assertEquals(fullFieldVar, relationship.getRelationTypeValue()); } finally { if (UtilMethods.isSet(parentContentType) && UtilMethods.isSet(parentContentType.id())) { contentTypeAPI.delete(parentContentType); } if (UtilMethods.isSet(childContentType) && UtilMethods.isSet(childContentType.id())) { contentTypeAPI.delete(childContentType); } } }