12
12
import com .fasterxml .jackson .databind .ObjectMapper ;
13
13
14
14
import org .junit .jupiter .api .BeforeEach ;
15
+ import org .junit .jupiter .api .DisplayName ;
15
16
import org .junit .jupiter .api .Test ;
16
17
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
17
18
import org .springframework .beans .factory .annotation .Autowired ;
21
22
import org .springframework .http .MediaType ;
22
23
import org .springframework .web .context .WebApplicationContext ;
23
24
25
+ import edu .kit .datamanager .pit .RecordTestHelper ;
26
+ import edu .kit .datamanager .pit .configuration .ApplicationProperties ;
27
+ import edu .kit .datamanager .pit .configuration .ApplicationProperties .ValidationStrategy ;
24
28
import edu .kit .datamanager .pit .domain .PIDRecord ;
29
+ import edu .kit .datamanager .pit .pidgeneration .PidSuffixGenerator ;
25
30
import edu .kit .datamanager .pit .pidlog .KnownPid ;
26
31
import edu .kit .datamanager .pit .pidlog .KnownPidsDao ;
27
32
import edu .kit .datamanager .pit .pidsystem .impl .HandleProtocolAdapter ;
28
33
import edu .kit .datamanager .pit .pidsystem .impl .InMemoryIdentifierSystem ;
29
34
import edu .kit .datamanager .pit .pidsystem .impl .local .LocalPidSystem ;
30
- import edu .kit .datamanager .pit .web . impl . TypingRESTResourceImpl ;
35
+ import edu .kit .datamanager .pit .pitservice . ITypingService ;
31
36
32
37
// org.springframework.mock is for unit testing
33
38
// Source: https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html
@@ -75,6 +80,15 @@ public class RestWithLocalPidSystemTest {
75
80
@ Autowired
76
81
private WebApplicationContext webApplicationContext ;
77
82
83
+ @ Autowired
84
+ private PidSuffixGenerator pidGenerator ;
85
+
86
+ @ Autowired
87
+ ITypingService typingService ;
88
+
89
+ @ Autowired
90
+ ApplicationProperties appProps ;
91
+
78
92
private MockMvc mockMvc ;
79
93
80
94
private ObjectMapper mapper ;
@@ -91,6 +105,7 @@ public void setup() throws Exception {
91
105
this .mockMvc = MockMvcBuilders .webAppContextSetup (this .webApplicationContext ).build ();
92
106
this .mapper = this .webApplicationContext .getBean ("OBJECT_MAPPER_BEAN" , ObjectMapper .class );
93
107
this .knownPidsDao .deleteAll ();
108
+ this .appProps .setValidationStrategy (ValidationStrategy .EMBEDDED_STRICT );
94
109
}
95
110
96
111
@ Test
@@ -163,6 +178,27 @@ public void testCreateValidRecord() throws Exception {
163
178
kp .getCreated ().isBefore (kp .getModified ());
164
179
}
165
180
181
+ @ Test
182
+ @ DisplayName ("Testing PID Records with usual/larger size, with the Local PID system (in-memory db)." )
183
+ public void testExtensiveRecord () throws Exception {
184
+ // create mockup of a large record. It contains non-registered PIDs and can not be validated.
185
+ this .appProps .setValidationStrategy (ValidationStrategy .NONE_DEBUG );
186
+ // as we use an in-memory db for testing, lets not make it too large.
187
+ int numAttributes = 100 ;
188
+ int numValues = 100 ;
189
+ assertTrue (numAttributes * numValues > 256 );
190
+ PIDRecord r = RecordTestHelper .getFakePidRecord (numAttributes , numValues , "sandboxed/" , pidGenerator );
191
+
192
+ String rJson = ApiMockUtils .serialize (r );
193
+ ApiMockUtils .registerRecord (
194
+ this .mockMvc ,
195
+ rJson ,
196
+ MediaType .APPLICATION_JSON_VALUE ,
197
+ MediaType .APPLICATION_JSON_VALUE ,
198
+ MockMvcResultMatchers .status ().isCreated ()
199
+ );
200
+ }
201
+
166
202
@ Test
167
203
public void testUpdateRecord () throws Exception {
168
204
PIDRecord record = this .createSomeRecord ();
0 commit comments