Search in sources :

Example 1 with TagSpec

use of com.icthh.xm.ms.entity.domain.spec.TagSpec in project xm-ms-entity by xm-online.

the class XmEntityGeneratorService method generateTags.

private Set<Tag> generateTags(TypeSpec typeSpec) {
    Set<Tag> tags = new HashSet<>();
    for (TagSpec tagSpec : randomCollectionElement(typeSpec.getTags())) {
        int countTags = RandomUtils.nextInt(1, MAX_TAGS_BY_TYPE);
        IntStream.range(0, countTags).forEach(i -> tags.add(createTag(tagSpec, i + 1)));
        log.debug("Generate {} tags for type {}", countTags, tagSpec.getKey());
    }
    return tags;
}
Also used : TagSpec(com.icthh.xm.ms.entity.domain.spec.TagSpec) Tag(com.icthh.xm.ms.entity.domain.Tag) HashSet(java.util.HashSet)

Example 2 with TagSpec

use of com.icthh.xm.ms.entity.domain.spec.TagSpec in project xm-ms-entity by xm-online.

the class XmEntityGeneratorServiceIntTest method generateXmEntityWithTagsTest.

@Test
@SneakyThrows
public void generateXmEntityWithTagsTest() {
    XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity(ENTITY_TYPE_WITH_TAGS_AND_LOCATIONS_KEY);
    log.info(new ObjectMapper().writeValueAsString(generatedEntity));
    Set<Tag> tags = generatedEntity.getTags();
    assertFalse("No tags generated", isEmpty(tags));
    TypeSpec specType = xmEntitySpecService.findTypeByKey("TYPE1.SUBTYPE1");
    List<TagSpec> tagsSpecs = specType.getTags();
    Set<String> specTagsKeys = tagsSpecs.stream().map(TagSpec::getKey).collect(toSet());
    Set<String> tagsKeys = tags.stream().map(Tag::getTypeKey).collect(toSet());
    assertTrue("Tag type not from tag specification", specTagsKeys.containsAll(tagsKeys));
    for (val tag : tags) {
        assertFalse("Name of tag is empty", isBlank(tag.getName()));
    }
}
Also used : lombok.val(lombok.val) TagSpec(com.icthh.xm.ms.entity.domain.spec.TagSpec) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Tag(com.icthh.xm.ms.entity.domain.Tag) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Aggregations

Tag (com.icthh.xm.ms.entity.domain.Tag)2 TagSpec (com.icthh.xm.ms.entity.domain.spec.TagSpec)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)1 TypeSpec (com.icthh.xm.ms.entity.domain.spec.TypeSpec)1 HashSet (java.util.HashSet)1 SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1