Skip to content

Commit 9d0932b

Browse files
committed
26908 Update managed_attribute_type postgres enum
Updated postgres enum + updated tests
1 parent ccebb9a commit 9d0932b

File tree

6 files changed

+78
-16
lines changed

6 files changed

+78
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ docker-compose.override.yml
88
/*.env
99
/*.idea
1010
/*.vscode
11+
/*.iml
1112
dbchangelog-4.4.xsd

src/main/resources/db/changelog/db.changelog-master.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
<include file="db/changelog/migrations/10-Update_jsonb_path_exists_varchar_function.xml"/>
1616
<include file="db/changelog/migrations/11-Align_managed_attribute_with_collection-api.xml"/>
1717
<include file="db/changelog/migrations/12-Add_support_for_type_Link.xml"/>
18+
<include file="db/changelog/migrations/13-Update_managed_attribute_type_postgres_enum.xml"/>
1819

1920
</databaseChangeLog>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no" ?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog db/changelog/xsd/dbchangelog-4.4.xsd"
5+
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
6+
7+
<changeSet id="13-Update_managed_attribute_type_postgres_enum" context="schema-change" author="cgendreau" runInTransaction="false">
8+
<sql>
9+
ALTER TYPE managed_attribute_type ADD VALUE 'DATE';
10+
</sql>
11+
<sql>
12+
ALTER TYPE managed_attribute_type ADD VALUE 'BOOL';
13+
</sql>
14+
</changeSet>
15+
</databaseChangeLog>

src/test/java/ca/gc/aafc/objectstore/api/repository/ObjectStoreManagedAttributeRepositoryCRUDIT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import javax.inject.Inject;
1010

1111
import ca.gc.aafc.objectstore.api.BaseIntegrationTest;
12+
import ca.gc.aafc.objectstore.api.testsupport.fixtures.ObjectStoreManagedAttributeFixture;
1213
import org.junit.jupiter.api.BeforeEach;
1314
import org.junit.jupiter.api.Test;
1415

@@ -62,12 +63,11 @@ public void findManagedAttribute_whenNoFieldsAreSelected_manageAttributeReturned
6263

6364
@Test
6465
public void create_WithAuthenticatedUser_SetsCreatedBy() {
65-
ObjectStoreManagedAttributeDto ma = new ObjectStoreManagedAttributeDto();
66-
ma.setUuid(UUID.randomUUID());
66+
ObjectStoreManagedAttributeDto ma = ObjectStoreManagedAttributeFixture
67+
.newObjectStoreManagedAttribute();
6768
ma.setName("name");
6869
ma.setManagedAttributeType(ManagedAttributeType.STRING);
6970
ma.setAcceptedValues(new String[] { "dosal" });
70-
ma.setMultilingualDescription(MultilingualDescriptionFactory.newMultilingualDescription().build());
7171

7272
ObjectStoreManagedAttributeDto result = managedResourceRepository.findOne(
7373
managedResourceRepository.create(ma).getUuid(),
@@ -77,13 +77,10 @@ public void create_WithAuthenticatedUser_SetsCreatedBy() {
7777

7878
@Test
7979
void findOneByKey_whenKeyProvided_managedAttributeFetched() {
80-
ObjectStoreManagedAttributeDto newAttribute = new ObjectStoreManagedAttributeDto();
80+
ObjectStoreManagedAttributeDto newAttribute = ObjectStoreManagedAttributeFixture
81+
.newObjectStoreManagedAttribute();
8182
newAttribute.setName("Object Store Attribute 1");
8283
newAttribute.setManagedAttributeType(ManagedAttributeType.INTEGER);
83-
newAttribute.setCreatedBy("poffm");
84-
newAttribute.setMultilingualDescription(
85-
MultilingualDescriptionFactory.newMultilingualDescription().build()
86-
);
8784

8885
UUID newAttributeUuid = managedResourceRepository.create(newAttribute).getUuid();
8986

src/test/java/ca/gc/aafc/objectstore/api/repository/ObjectStoreMetadataRepositoryCRUDIT.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package ca.gc.aafc.objectstore.api.repository;
22

3+
import ca.gc.aafc.dina.entity.ManagedAttribute;
34
import ca.gc.aafc.objectstore.api.BaseIntegrationTest;
5+
import ca.gc.aafc.objectstore.api.dto.ObjectStoreManagedAttributeDto;
46
import ca.gc.aafc.objectstore.api.dto.ObjectStoreMetadataDto;
57
import ca.gc.aafc.objectstore.api.dto.ObjectSubtypeDto;
68
import ca.gc.aafc.objectstore.api.entities.Derivative;
79
import ca.gc.aafc.objectstore.api.entities.ObjectStoreManagedAttribute;
810
import ca.gc.aafc.objectstore.api.entities.ObjectStoreMetadata;
911
import ca.gc.aafc.objectstore.api.entities.ObjectSubtype;
1012
import ca.gc.aafc.objectstore.api.entities.ObjectUpload;
11-
import ca.gc.aafc.objectstore.api.testsupport.factories.MultilingualDescriptionFactory;
1213
import ca.gc.aafc.objectstore.api.testsupport.factories.ObjectStoreManagedAttributeFactory;
1314
import ca.gc.aafc.objectstore.api.testsupport.factories.ObjectStoreMetadataFactory;
1415
import ca.gc.aafc.objectstore.api.testsupport.factories.ObjectSubtypeFactory;
1516
import ca.gc.aafc.objectstore.api.testsupport.factories.ObjectUploadFactory;
17+
import ca.gc.aafc.objectstore.api.testsupport.fixtures.ObjectStoreManagedAttributeFixture;
1618
import io.crnk.core.queryspec.QuerySpec;
1719
import org.apache.commons.lang3.RandomStringUtils;
1820
import org.junit.jupiter.api.AfterEach;
@@ -36,7 +38,8 @@ public class ObjectStoreMetadataRepositoryCRUDIT extends BaseIntegrationTest {
3638
@Inject
3739
private ObjectStoreResourceRepository objectStoreResourceRepository;
3840

39-
private ObjectStoreManagedAttribute testManagedAttribute;
41+
@Inject
42+
private ObjectStoreManagedAttributeResourceRepository managedResourceRepository;
4043

4144
private ObjectSubtypeDto acSubtype;
4245

@@ -48,19 +51,17 @@ private ObjectStoreMetadata createTestObjectStoreMetadata() {
4851
return testObjectStoreMetadata;
4952
}
5053

51-
private void createTestManagedAttribute() {
52-
testManagedAttribute = ObjectStoreManagedAttributeFactory.newManagedAttribute()
53-
.acceptedValues(new String[]{"dosal"})
54-
.multilingualDescription(MultilingualDescriptionFactory.newMultilingualDescription().build())
54+
private ObjectStoreManagedAttribute createTestManagedAttribute() {
55+
ObjectStoreManagedAttribute testManagedAttribute = ObjectStoreManagedAttributeFactory.newManagedAttribute()
56+
.acceptedValues(new String[]{"dorsal"})
5557
.build();
56-
managedAttributeService.create(testManagedAttribute);
58+
return managedAttributeService.create(testManagedAttribute);
5759
}
5860

5961
@BeforeEach
6062
public void setup() {
6163
objectUpload = createObjectUpload();
6264
createAcSubtype();
63-
createTestManagedAttribute();
6465
}
6566

6667
/**
@@ -109,6 +110,9 @@ public void findMeta_whenNoFieldsAreSelected_MetadataReturnedWithAllFields() {
109110

110111
@Test
111112
public void create_ValidResource_ResourcePersisted() {
113+
114+
ObjectStoreManagedAttribute testManagedAttribute = createTestManagedAttribute();
115+
112116
ObjectUpload objectUploadTest = ObjectUploadFactory.newObjectUpload().build();
113117
objectUploadService.create(objectUploadTest);
114118

@@ -219,6 +223,31 @@ private void assertRelationshipsRemoved(UUID metadataUUID) {
219223
ObjectStoreMetadata result = objectStoreMetaDataService.findOne(updateMetadataDto.getUuid());
220224
Assertions.assertNull(result.getAcSubtype());
221225
}
226+
227+
@Test
228+
public void create_onManagedAttributeValue_validationOccur() {
229+
230+
ObjectStoreManagedAttributeDto newAttribute = ObjectStoreManagedAttributeFixture.newObjectStoreManagedAttribute();
231+
newAttribute.setManagedAttributeType(ManagedAttribute.ManagedAttributeType.DATE);
232+
newAttribute.setAcceptedValues(null);
233+
newAttribute = managedResourceRepository.create(newAttribute);
234+
235+
ObjectStoreMetadata testMetadata = createTestObjectStoreMetadata();
236+
ObjectStoreMetadataDto testMetadataDto = fetchMetaById(testMetadata.getUuid());
237+
238+
// Put an invalid value for Date
239+
testMetadataDto.setManagedAttributeValues(Map.of(newAttribute.getKey(), "zxy"));
240+
assertThrows(ValidationException.class, () -> objectStoreResourceRepository.save(testMetadataDto));
241+
242+
// Fix the value
243+
testMetadataDto.setManagedAttributeValues(Map.of(newAttribute.getKey(), "2022-02-02"));
244+
objectStoreResourceRepository.save(testMetadataDto);
245+
246+
//cleanup
247+
objectStoreResourceRepository.delete(testMetadata.getUuid());
248+
249+
// can't delete managed attribute for now since the check for key in use is using a fresh transaction
250+
}
222251

223252
private ObjectStoreMetadataDto newMetaDto() {
224253
ObjectStoreMetadataDto parentDTO = new ObjectStoreMetadataDto();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ca.gc.aafc.objectstore.api.testsupport.fixtures;
2+
3+
import ca.gc.aafc.objectstore.api.dto.ObjectStoreManagedAttributeDto;
4+
import ca.gc.aafc.objectstore.api.testsupport.factories.MultilingualDescriptionFactory;
5+
import org.apache.commons.lang3.RandomStringUtils;
6+
7+
public class ObjectStoreManagedAttributeFixture {
8+
9+
public static ObjectStoreManagedAttributeDto newObjectStoreManagedAttribute() {
10+
ObjectStoreManagedAttributeDto collectionManagedAttributeDto = new ObjectStoreManagedAttributeDto();
11+
collectionManagedAttributeDto.setName(RandomStringUtils.randomAlphabetic(5));
12+
collectionManagedAttributeDto.setAcceptedValues(new String[]{"value"});
13+
collectionManagedAttributeDto.setCreatedBy("created by");
14+
collectionManagedAttributeDto.setMultilingualDescription(
15+
MultilingualDescriptionFactory.newMultilingualDescription().build()
16+
);
17+
return collectionManagedAttributeDto;
18+
}
19+
}

0 commit comments

Comments
 (0)