protected List<EventClassFamily> generateEventClassFamily(Tenant tenant, int count) { if (tenant == null) { tenant = generateTenant(); } EventClassFamily eventClassFamily; List<EventClassFamily> eventClassFamilies = new ArrayList<>(count); for (int i = 0; i < count; i++) { eventClassFamily = new EventClassFamily(); eventClassFamily.setTenant(tenant); eventClassFamily.setClassName("Test ClassName" + RANDOM.nextInt()); eventClassFamily.setCreatedTime(new Date().getTime()); eventClassFamily.setCreatedUsername("Test Username"); eventClassFamily.setDescription("Test Description"); eventClassFamily.setName("Test Name" + RANDOM.nextInt()); eventClassFamily.setNamespace("Test Namespace"); eventClassFamily = eventClassFamilyDao.save(eventClassFamily); Assert.assertNotNull(eventClassFamily); eventClassFamilies.add(eventClassFamily); } return eventClassFamilies; }
@Override public Set<String> getFqnSetForEcf(String ecfId) { if (isValidSqlId(ecfId)) { LOG.debug("Get fqn list for event class family by id [{}] ", ecfId); Set<String> storedFqns = new HashSet<>(); EventClassFamily ecf = eventClassFamilyDao.findById(ecfId); ecf.getSchemas().forEach(ecfv -> ecfv.getRecords() .forEach(ec -> storedFqns.add(ec.getFqn()))); return storedFqns; } else { throw new IncorrectParameterException("Incorrect event class family id: " + ecfId); } } }
return false; } else if (!ecf.equals(other.ecf)) { return false;
for (EventClassFamily eventClassFamily : eventClassFamilies) { if (eventClassFamily.getSchemas() != null) { for (EventClassFamilyVersion eventClassFamilyVersion : eventClassFamily.getSchemas()) { EcfInfoDto ecf = new EcfInfoDto(); ecf.setEcfId(String.valueOf(eventClassFamily.getId())); ecf.setEcfName(eventClassFamily.getName()); ecf.setVersion(eventClassFamilyVersion.getVersion()); if (occupiedEcfs != null && !occupiedEcfs.contains(ecf)) {
@Test public void findByTenantIdTest() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamilies.get(0).getStringId()); Assert.assertNotNull(dto); List<EventClassFamily> eventClassFamilyList = eventClassFamilyDao.findByTenantId(dto.getTenant().getStringId()); EventClassFamily eventClassFamily = null; for (EventClassFamily found : eventClassFamilyList) { if (dto.getId().equals(found.getId())) { eventClassFamily = found; } } Assert.assertNotNull(eventClassFamily); Assert.assertEquals(dto, eventClassFamily); }
@Test public void findByTenantIdAndNameTest() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamilies.get(0).getStringId()); Assert.assertNotNull(dto); EventClassFamily eventClassFamily = eventClassFamilyDao.findByTenantIdAndName(dto.getTenant().getStringId(), dto.getName()); Assert.assertNotNull(eventClassFamily); Assert.assertEquals(dto, eventClassFamily); }
protected List<EventClass> generateEventClass(Tenant tenant, EventClassFamily eventClassFamily, int count) { if (tenant == null) { tenant = generateTenant(); } if (eventClassFamily == null) { eventClassFamily = generateEventClassFamily(tenant, 1).get(0); } List<EventClassFamilyVersion> ecfvList = generateEventClassFamilyVersion(eventClassFamily, 1, count); eventClassFamily.setSchemas(ecfvList); eventClassFamily = eventClassFamilyDao.save(eventClassFamily); List<EventClass> storedECs = eventClassFamily.getSchemas().get(0).getRecords(); return storedECs; }
EventClassFamily ecf = new EventClassFamily(eventClassFamily); ecf.setSchemas(schemas); eventClassFamilyDao.save(ecf); } else {
@Override public ApplicationEventFamilyMapDto toDto() { ApplicationEventFamilyMapDto dto = createDto(); dto.setId(getStringId()); if (application != null) { dto.setApplicationId(application.getStringId()); } if (ecf != null) { dto.setEcfId(ecf.getStringId()); dto.setEcfName(ecf.getName()); } dto.setVersion(version); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); if (eventMaps != null) { List<ApplicationEventMapDto> eventMapsDto = new ArrayList<>(eventMaps.size()); for (ApplicationEventMap eventMap : eventMaps) { eventMapsDto.add(eventMap.toDto()); } dto.setEventMaps(eventMapsDto); } return dto; }
@Override public EventClassFamilyDto toDto() { EventClassFamilyDto dto = createDto(); dto.setId(getStringId()); if (tenant != null) { dto.setTenantId(tenant.getStringId()); } dto.setName(name); dto.setNamespace(namespace); dto.setClassName(className); dto.setDescription(description); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); return dto; }
@Test public void removeByTenantId() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily eventClassFamily = eventClassFamilies.get(0); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNotNull(dto); Assert.assertNotNull(dto.getTenant()); eventClassFamilyDao.removeByTenantId(dto.getTenant().getStringId()); dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNull(dto); }
@Override protected GenericModel<EventClassFamilyDto> newInstance(Long id) { return new EventClassFamily(id); }
@Test public void testFindByEcfIdAndVersion() { List<ApplicationEventFamilyMap> applicationEventFamilyMaps = generateApplicationEventFamilyMap(null, null, null, 2, true); ApplicationEventFamilyMap aefm = applicationEventFamilyMaps.get(0); List<ApplicationEventFamilyMap> found = applicationEventFamilyMapDao.findByEcfIdAndVersion(aefm.getEcf().getId().toString(), aefm.getVersion()); Assert.assertEquals(applicationEventFamilyMaps, found); } }
@Test public void removeById() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 2); EventClassFamily eventClassFamily = eventClassFamilies.get(0); EventClassFamily dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNotNull(dto); eventClassFamilyDao.removeById(eventClassFamily.getStringId()); dto = eventClassFamilyDao.findById(eventClassFamily.getStringId()); Assert.assertNull(dto); }
@Test public void testFindByTenantIdAndFqn() { EventClassFamily classFamily = generateEventClassFamily(null, 1).get(0); Tenant tenant = classFamily.getTenant(); List<EventClass> events = generateEventClass(tenant, classFamily, 3); EventClass ec = events.get(0); List<EventClass> found = eventClassDao.findByTenantIdAndFqn(tenant.getId().toString(), ec.getFqn()); Assert.assertEquals(ec, found.get(0)); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((application == null) ? 0 : application.hashCode()); result = prime * result + (int) (createdTime ^ (createdTime >>> 32)); result = prime * result + ((createdUsername == null) ? 0 : createdUsername.hashCode()); result = prime * result + ((ecf == null) ? 0 : ecf.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + version; return result; }
@Test public void findByEcfvIdTest() { List<EventClassFamily> eventClassFamilies = generateEventClassFamily(null, 1); EventClassFamily ecf = eventClassFamilies.get(0); List<EventClassFamilyVersion> ecfvList = generateEventClassFamilyVersion(ecf, 1, 1); ecf.setSchemas(ecfvList); ecf = eventClassFamilyDao.save(ecf); EventClassFamilyVersion ecfv = ecfvList.get(0); EventClassFamily ecfByEcfv = eventClassFamilyDao.findByEcfvId(ecfv.getStringId()); Assert.assertNotNull(ecfByEcfv); Assert.assertEquals(ecf, ecfByEcfv); Assert.assertEquals(ecfByEcfv.getSchemas().size(), 1); if (ecfByEcfv.getSchemas().size() == 1) { Assert.assertEquals(ecfByEcfv.getSchemas().get(0).getRecords().size(), 1); } else { throw new AssertionError("There should be 1 ecfv in fetched ecf, but got: " + ecfByEcfv.getSchemas().size()); } } }
/** * Create new instance of <code>ApplicationEventFamilyMap</code>. * * @param dto data transfer object */ public ApplicationEventFamilyMap(ApplicationEventFamilyMapDto dto) { this.id = getLongId(dto.getId()); Long applicationId = getLongId(dto.getApplicationId()); if (applicationId != null) { this.application = new Application(applicationId); } Long ecfId = getLongId(dto.getEcfId()); if (ecfId != null) { this.ecf = new EventClassFamily(ecfId); } this.version = dto.getVersion(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); if (dto.getEventMaps() != null) { this.eventMaps = new ArrayList<>(dto.getEventMaps().size()); for (ApplicationEventMapDto eventMap : dto.getEventMaps()) { this.eventMaps.add(new ApplicationEventMap(eventMap)); } } }
@Test public void testValidateApplicationEventFamilyMap() { List<ApplicationEventFamilyMap> applicationEventFamilyMaps = generateApplicationEventFamilyMap(null, null, null, 2, true); ApplicationEventFamilyMap aefm = applicationEventFamilyMaps.get(0); boolean result = applicationEventFamilyMapDao.validateApplicationEventFamilyMap(aefm.getApplication().getId().toString(), aefm.getEcf().getId() .toString(), aefm.getVersion()); Assert.assertFalse(result); result = applicationEventFamilyMapDao.validateApplicationEventFamilyMap("7", "7", 7); Assert.assertTrue(result); }
protected List<EventClassFamilyVersion> generateEventClassFamilyVersion(EventClassFamily eventClassFamily, int ecfvCount, int ecCount) { List<EventClassFamilyVersion> ecfvList = new ArrayList<>(ecfvCount); for (int i = 0; i < ecfvCount; i++) { EventClassFamilyVersion ecfv = new EventClassFamilyVersion(); List<EventClass> ecList = new ArrayList<>(); for (int j = 0; j < ecCount; j++) { EventClass ec = new EventClass(); ec.setTenant(eventClassFamily.getTenant()); Optional<CtlSchema> ctlMaxVersion = ctlSchemaDao.find().stream() .max((ctl1, ctl2) -> Integer.compare(ctl1.getVersion(), ctl2.getVersion())); int version = ctlMaxVersion.isPresent() ? (ctlMaxVersion.get().getVersion() + 1) : 1; ec.setCtlSchema(generateCTLSchema(DEFAULT_FQN, version, eventClassFamily.getTenant(), CTLSchemaScopeDto.TENANT)); ec.setEcfv(ecfv); ec.setFqn("Test FQN" + RANDOM.nextInt()); ec.setType(EventClassType.EVENT); ecList.add(ec); } ecfv.setRecords(ecList); ecfvList.add(ecfv); } return ecfvList; }