Commit 590ae6bb authored by Nikita Ruzhevsky's avatar Nikita Ruzhevsky
Browse files

WIP: schema info store tests

parent d5642790
Pipeline #60301 passed with stages
in 4 minutes and 42 seconds
package org.opengroup.osdu.core.mongodb.schema.integration;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.mongodb.schema.config.MongoEmbeddedConfig;
import org.opengroup.osdu.core.mongodb.schema.config.SchemaTestConfig;
import org.opengroup.osdu.core.mongodb.schema.dto.SchemaIdentityDto;
import org.opengroup.osdu.core.mongodb.schema.dto.SchemaInfoDto;
import org.opengroup.osdu.core.mongodb.schema.entity.EntityId;
import org.opengroup.osdu.core.mongodb.schema.entity.SchemaIdentityDoc;
import org.opengroup.osdu.core.mongodb.schema.entity.SchemaInfoDoc;
import org.opengroup.osdu.core.mongodb.schema.entity.SchemaScope;
import org.opengroup.osdu.core.mongodb.schema.entity.SchemaStatus;
import org.opengroup.osdu.core.mongodb.schema.helper.SchemaInfoStoreHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MongoEmbeddedConfig.class, SchemaTestConfig.class})
public class SchemaInfoStoreTests {
private static final Class<SchemaInfoDoc> CLASS = SchemaInfoDoc.class;
private static final String TENANT = "int-test-schema";
@Autowired
MongoTemplate mongoTemplate;
@Autowired
SchemaInfoStoreHelper schemaInfoStoreHelper;
@BeforeClass
public static void init() {
MongoEmbeddedConfig.init();
}
@After
public void cleanup() {
mongoTemplate.remove(new Query(), CLASS);
}
@Test
public void applicationStarts() {
public void getInfo() {
// given
String id = "test-id";
SchemaInfoDoc doc = createSchemaDoc(id, TENANT);
mongoTemplate.save(doc);
// when
SchemaInfoDto dto = schemaInfoStoreHelper.getSchemaInfo(id, TENANT);
// then
assertThatDtoFieldsNotNull(dto);
}
@Test(expected = IllegalArgumentException.class)
public void getInfo_fails_notFound() {
schemaInfoStoreHelper.getSchemaInfo("wrong-id", TENANT);
}
@Test
public void createSchemaInfo() {
// given
String id = "test-schema";
SchemaInfoDto dto = createSchemaDto(id);
// when
schemaInfoStoreHelper.createSchemaInfo(dto, TENANT);
// then
SchemaInfoDoc doc = mongoTemplate.findById(new EntityId(id, TENANT), CLASS);
assertThatDocFieldsNotNull(doc);
}
@Test(expected = IllegalArgumentException.class)
public void createSchemaInfo_failedForSameId() {
SchemaInfoDto dto = createSchemaDto("test-id");
// when
schemaInfoStoreHelper.createSchemaInfo(dto, TENANT);
schemaInfoStoreHelper.createSchemaInfo(dto, TENANT);
}
@Test
public void updateSchemaInfo() {
}
private void assertThatDtoFieldsNotNull(SchemaInfoDto dto) {
assertThat(dto).isNotNull();
assertThat(dto.getScope()).isNotNull();
assertThat(dto.getCreatedBy()).isNotNull();
assertThat(dto.getDateCreated()).isNotNull();
assertThat(dto.getStatus()).isNotNull();
assertThat(dto.getSchemaIdentity()).isNotNull();
assertThat(dto.getSchemaIdentity().getId()).isNotNull();
assertThat(dto.getSchemaIdentity().getAuthority()).isNotNull();
assertThat(dto.getSchemaIdentity().getEntityType()).isNotNull();
assertThat(dto.getSchemaIdentity().getSource()).isNotNull();
assertThat(dto.getSchemaIdentity().getSchemaVersionMajor()).isNotNull();
assertThat(dto.getSchemaIdentity().getSchemaVersionMinor()).isNotNull();
assertThat(dto.getSchemaIdentity().getSchemaVersionPatch()).isNotNull();
assertThat(dto.getSupersededBy()).isNotNull();
assertThat(dto.getSupersededBy().getId()).isNotNull();
assertThat(dto.getSupersededBy().getAuthority()).isNotNull();
assertThat(dto.getSupersededBy().getEntityType()).isNotNull();
assertThat(dto.getSupersededBy().getSource()).isNotNull();
assertThat(dto.getSupersededBy().getSchemaVersionMajor()).isNotNull();
assertThat(dto.getSupersededBy().getSchemaVersionMinor()).isNotNull();
assertThat(dto.getSupersededBy().getSchemaVersionPatch()).isNotNull();
}
private void assertThatDocFieldsNotNull(SchemaInfoDoc doc) {
assertThat(doc).isNotNull();
assertThat(doc.getId()).isNotNull();
assertThat(doc.getTenant()).isNotNull();
assertThat(doc.getScope()).isNotNull();
assertThat(doc.getCreatedBy()).isNotNull();
assertThat(doc.getDateCreated()).isNotNull();
assertThat(doc.getStatus()).isNotNull();
assertThat(doc.getSchemaIdentity()).isNotNull();
assertThat(doc.getSchemaIdentity().getId()).isNotNull();
assertThat(doc.getSchemaIdentity().getAuthority()).isNotNull();
assertThat(doc.getSchemaIdentity().getEntityType()).isNotNull();
assertThat(doc.getSchemaIdentity().getSource()).isNotNull();
assertThat(doc.getSchemaIdentity().getSchemaVersionMajor()).isNotNull();
assertThat(doc.getSchemaIdentity().getSchemaVersionMinor()).isNotNull();
assertThat(doc.getSchemaIdentity().getSchemaVersionPatch()).isNotNull();
assertThat(doc.getSupersededBy()).isNotNull();
assertThat(doc.getSupersededBy().getId()).isNotNull();
assertThat(doc.getSupersededBy().getAuthority()).isNotNull();
assertThat(doc.getSupersededBy().getEntityType()).isNotNull();
assertThat(doc.getSupersededBy().getSource()).isNotNull();
assertThat(doc.getSupersededBy().getSchemaVersionMajor()).isNotNull();
assertThat(doc.getSupersededBy().getSchemaVersionMinor()).isNotNull();
assertThat(doc.getSupersededBy().getSchemaVersionPatch()).isNotNull();
}
private SchemaInfoDoc createSchemaDoc(String id, String tenant) {
SchemaInfoDoc doc = new SchemaInfoDoc();
SchemaIdentityDoc identity = new SchemaIdentityDoc();
identity.setId(id);
identity.setAuthority("authority");
identity.setSchemaVersionMajor(1L);
identity.setSchemaVersionMinor(1L);
identity.setSchemaVersionPatch(1L);
identity.setEntityType("test");
identity.setSource("src");
SchemaIdentityDoc superSeed = new SchemaIdentityDoc();
superSeed.setId("super");
superSeed.setAuthority("authority");
superSeed.setSchemaVersionMajor(1L);
superSeed.setSchemaVersionMinor(1L);
superSeed.setSchemaVersionPatch(1L);
superSeed.setEntityType("test");
superSeed.setSource("src");
doc.setSchemaIdentity(identity);
doc.setSupersededBy(superSeed);
doc.setCreatedBy("created by test");
doc.setScope(SchemaScope.SHARED);
doc.setDateCreated(new Date());
doc.setStatus(SchemaStatus.PUBLISHED);
doc.setId(new EntityId(id, tenant));
doc.setTenant(tenant);
return doc;
}
private SchemaInfoDto createSchemaDto(String id) {
SchemaInfoDto dto = new SchemaInfoDto();
SchemaIdentityDto identity = new SchemaIdentityDto();
identity.setId(id);
identity.setAuthority("authority");
identity.setSchemaVersionMajor(1L);
identity.setSchemaVersionMinor(1L);
identity.setSchemaVersionPatch(1L);
identity.setEntityType("test");
identity.setSource("src");
SchemaIdentityDto superSeed = new SchemaIdentityDto();
superSeed.setId("super");
superSeed.setAuthority("authority");
superSeed.setSchemaVersionMajor(1L);
superSeed.setSchemaVersionMinor(1L);
superSeed.setSchemaVersionPatch(1L);
superSeed.setEntityType("test");
superSeed.setSource("src");
dto.setSchemaIdentity(identity);
dto.setSupersededBy(superSeed);
dto.setCreatedBy("created by test");
dto.setScope(SchemaScope.SHARED);
dto.setDateCreated(new Date());
dto.setStatus(SchemaStatus.PUBLISHED);
return dto;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment