@Test public void testGetNaturalKeyDescriptor() throws NoNaturalKeysDefinedException { Entity e = setup(); TenantContext.setTenantId("someTenant"); NaturalKeyDescriptor desc = naturalKeyExtractor.getNaturalKeyDescriptor(e); Map<String, String> naturalKeys = desc.getNaturalKeys(); Assert.assertEquals(COLLECTION_TYPE, desc.getEntityType()); Assert.assertEquals("someTenant", desc.getTenantId()); Assert.assertEquals(1, naturalKeys.size()); Assert.assertEquals("someValue", naturalKeys.get("someField")); Mockito.verify(entitySchemaRegistry, Mockito.times(2)).getSchema(Mockito.anyString()); }
@Override public NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity) throws NoNaturalKeysDefinedException { Map<String, String> map = getNaturalKeys(entity); if (map == null) { NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(); naturalKeyDescriptor.setNaturalKeysNotNeeded(true); return naturalKeyDescriptor; } String entityType = getCollectionName(entity); String tenantId = TenantContext.getTenantId(); String parentId = retrieveParentId(entity); NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(map, tenantId, entityType, parentId); return naturalKeyDescriptor; }
NaturalKeyExtractor implements INaturalKeyExtractor { @Override public NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity) throws NoNaturalKeysDefinedException { Map<String, String> map = getNaturalKeys(entity); if (map == null) { NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(); naturalKeyDescriptor.setNaturalKeysNotNeeded(true); return naturalKeyDescriptor; } String entityType = getCollectionName(entity); String tenantId = TenantContext.getTenantId(); String parentId = retrieveParentId(entity); NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(map, tenantId, entityType, parentId); return naturalKeyDescriptor; } }
NaturalKeyExtractor implements INaturalKeyExtractor { @Override public NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity) throws NoNaturalKeysDefinedException { Map<String, String> map = getNaturalKeys(entity); if (map == null) { NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(); naturalKeyDescriptor.setNaturalKeysNotNeeded(true); return naturalKeyDescriptor; } String entityType = getCollectionName(entity); String tenantId = TenantContext.getTenantId(); String parentId = retrieveParentId(entity); NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(map, tenantId, entityType, parentId); return naturalKeyDescriptor; }  }
NaturalKeyExtractor implements INaturalKeyExtractor { @Override public NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity) throws NoNaturalKeysDefinedException { Map<String, String> map = getNaturalKeys(entity); if (map == null) { NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(); naturalKeyDescriptor.setNaturalKeysNotNeeded(true); return naturalKeyDescriptor; } String entityType = getCollectionName(entity); String tenantId = TenantContext.getTenantId(); String parentId = retrieveParentId(entity); NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(map, tenantId, entityType, parentId); return naturalKeyDescriptor; }  @Override Map<String, String> getNaturalKeys(Entity entity); @Override Map<String, Boolean> getNaturalKeyFields(Entity entity); @Override NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity); String getCollectionName(Entity entity); }
NaturalKeyExtractor implements INaturalKeyExtractor { @Override public NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity) throws NoNaturalKeysDefinedException { Map<String, String> map = getNaturalKeys(entity); if (map == null) { NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(); naturalKeyDescriptor.setNaturalKeysNotNeeded(true); return naturalKeyDescriptor; } String entityType = getCollectionName(entity); String tenantId = TenantContext.getTenantId(); String parentId = retrieveParentId(entity); NaturalKeyDescriptor naturalKeyDescriptor = new NaturalKeyDescriptor(map, tenantId, entityType, parentId); return naturalKeyDescriptor; }  @Override Map<String, String> getNaturalKeys(Entity entity); @Override Map<String, Boolean> getNaturalKeyFields(Entity entity); @Override NaturalKeyDescriptor getNaturalKeyDescriptor(Entity entity); String getCollectionName(Entity entity);  }