1
+ #! /usr/bin/env groovy
2
+
3
+ /**
4
+ * Copyright (c) 2018 Informatics Matters Ltd.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ /**
20
+ * The MediaTypes class. A class to provide validation of files produced
21
+ * by an executing pipeline.
22
+ */
23
+ class MediaChecker {
24
+
25
+ final static String mediaTypesFile = ' MediaTypes.txt'
26
+
27
+ // A map of media type and expected file extension(s).
28
+ // This is populated by the constructor, which reads the content
29
+ // of 'mediaTypesFile'.
30
+ def mediaTypesLookup = null
31
+
32
+ /**
33
+ * Default constructor.
34
+ * Reads media types config file.
35
+ */
36
+ MediaChecker () {
37
+
38
+ mediaTypesLookup = new ConfigSlurper (). parse(new File (mediaTypesFile). toURI(). toURL())
39
+
40
+ }
41
+
42
+ /**
43
+ * Checks that a pipeline's expected files exist.
44
+ *
45
+ * @param serviceDescriptor The test service descriptor
46
+ * @param path The test path (where the pipeline's files are to be found)
47
+ * @return True on success, False otherwise.
48
+ */
49
+ boolean check (serviceDescriptor , File path ) {
50
+
51
+ boolean retVal = true
52
+
53
+ // Check output descriptors for expected output file names...
54
+ // Do all, regardless of individual failure.
55
+ def opDescriptors = serviceDescriptor. serviceConfig. outputDescriptors
56
+ opDescriptors. each { desc ->
57
+
58
+ // Expected extension...
59
+ // (use the media type to lookup it up)
60
+ // And construct full path to the expected file...
61
+ String opExt = mediaTypesLookup. media_type[desc. mediaType]
62
+ String opName = desc. name + opExt
63
+ String opPath = path. toString() + File . separator + opName
64
+ if (! new File (opPath). exists()) {
65
+ Log . err(" The pipeline's 'outputDescriptor'" +
66
+ " expected '$opName ' but the file wasn't found" )
67
+ retVal = false
68
+ }
69
+
70
+ }
71
+
72
+ return retVal
73
+
74
+ }
75
+
76
+ }
0 commit comments