1
1
package ca .gc .aafc .objectstore .api .repository ;
2
2
3
+ import ca .gc .aafc .dina .entity .ManagedAttribute ;
3
4
import ca .gc .aafc .objectstore .api .BaseIntegrationTest ;
5
+ import ca .gc .aafc .objectstore .api .dto .ObjectStoreManagedAttributeDto ;
4
6
import ca .gc .aafc .objectstore .api .dto .ObjectStoreMetadataDto ;
5
7
import ca .gc .aafc .objectstore .api .dto .ObjectSubtypeDto ;
6
8
import ca .gc .aafc .objectstore .api .entities .Derivative ;
7
9
import ca .gc .aafc .objectstore .api .entities .ObjectStoreManagedAttribute ;
8
10
import ca .gc .aafc .objectstore .api .entities .ObjectStoreMetadata ;
9
11
import ca .gc .aafc .objectstore .api .entities .ObjectSubtype ;
10
12
import ca .gc .aafc .objectstore .api .entities .ObjectUpload ;
11
- import ca .gc .aafc .objectstore .api .testsupport .factories .MultilingualDescriptionFactory ;
12
13
import ca .gc .aafc .objectstore .api .testsupport .factories .ObjectStoreManagedAttributeFactory ;
13
14
import ca .gc .aafc .objectstore .api .testsupport .factories .ObjectStoreMetadataFactory ;
14
15
import ca .gc .aafc .objectstore .api .testsupport .factories .ObjectSubtypeFactory ;
15
16
import ca .gc .aafc .objectstore .api .testsupport .factories .ObjectUploadFactory ;
17
+ import ca .gc .aafc .objectstore .api .testsupport .fixtures .ObjectStoreManagedAttributeFixture ;
16
18
import io .crnk .core .queryspec .QuerySpec ;
17
19
import org .apache .commons .lang3 .RandomStringUtils ;
18
20
import org .junit .jupiter .api .AfterEach ;
@@ -36,7 +38,8 @@ public class ObjectStoreMetadataRepositoryCRUDIT extends BaseIntegrationTest {
36
38
@ Inject
37
39
private ObjectStoreResourceRepository objectStoreResourceRepository ;
38
40
39
- private ObjectStoreManagedAttribute testManagedAttribute ;
41
+ @ Inject
42
+ private ObjectStoreManagedAttributeResourceRepository managedResourceRepository ;
40
43
41
44
private ObjectSubtypeDto acSubtype ;
42
45
@@ -48,19 +51,17 @@ private ObjectStoreMetadata createTestObjectStoreMetadata() {
48
51
return testObjectStoreMetadata ;
49
52
}
50
53
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" })
55
57
.build ();
56
- managedAttributeService .create (testManagedAttribute );
58
+ return managedAttributeService .create (testManagedAttribute );
57
59
}
58
60
59
61
@ BeforeEach
60
62
public void setup () {
61
63
objectUpload = createObjectUpload ();
62
64
createAcSubtype ();
63
- createTestManagedAttribute ();
64
65
}
65
66
66
67
/**
@@ -109,6 +110,9 @@ public void findMeta_whenNoFieldsAreSelected_MetadataReturnedWithAllFields() {
109
110
110
111
@ Test
111
112
public void create_ValidResource_ResourcePersisted () {
113
+
114
+ ObjectStoreManagedAttribute testManagedAttribute = createTestManagedAttribute ();
115
+
112
116
ObjectUpload objectUploadTest = ObjectUploadFactory .newObjectUpload ().build ();
113
117
objectUploadService .create (objectUploadTest );
114
118
@@ -219,6 +223,31 @@ private void assertRelationshipsRemoved(UUID metadataUUID) {
219
223
ObjectStoreMetadata result = objectStoreMetaDataService .findOne (updateMetadataDto .getUuid ());
220
224
Assertions .assertNull (result .getAcSubtype ());
221
225
}
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
+ }
222
251
223
252
private ObjectStoreMetadataDto newMetaDto () {
224
253
ObjectStoreMetadataDto parentDTO = new ObjectStoreMetadataDto ();
0 commit comments