fa79f89215b7e0b1dc6f35a4b3598da589cb7502
[policy/apex-pdp.git] / model / engine-model / src / test / java / org / onap / policy / apex / model / enginemodel / handling / DummyTestApexEngineModelCreator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.enginemodel.handling;
22
23 import java.util.UUID;
24
25 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
26 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
29 import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
30 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
31 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
32 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
33 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
34 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
35 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
36 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats;
37
38 public class DummyTestApexEngineModelCreator implements TestApexModelCreator<AxEngineModel> {
39
40     @Override
41     public AxEngineModel getModel() {
42         final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
43                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
44         final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
45                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
46
47         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
48         schemas.getSchemasMap().put(schema0.getKey(), schema0);
49         schemas.getSchemasMap().put(schema1.getKey(), schema1);
50
51         final AxContextAlbum album0 =
52                 new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema1.getKey());
53
54         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
55         albums.getAlbumsMap().put(album0.getKey(), album0);
56
57         final AxEngineModel engineModel = new AxEngineModel(new AxArtifactKey("AnEngine", "0.0.1"));
58         engineModel.setSchemas(schemas);
59         engineModel.setAlbums(albums);
60         engineModel.setTimestamp(System.currentTimeMillis());
61         engineModel.setState(AxEngineState.EXECUTING);
62         engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
63                 System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
64         engineModel.getKeyInformation().generateKeyInfo(engineModel);
65
66         final AxValidationResult result = new AxValidationResult();
67         engineModel.validate(result);
68
69         return engineModel;
70     }
71
72     @Override
73     public AxEngineModel getInvalidModel() {
74         final AxEngineModel engineModel = getModel();
75
76         engineModel.setTimestamp(System.currentTimeMillis());
77         engineModel.setState(AxEngineState.UNDEFINED);
78         engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
79                 System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
80         engineModel.getKeyInformation().generateKeyInfo(engineModel);
81
82         return engineModel;
83     }
84
85     /**
86      * Get a malstructured model.
87      */
88     public AxEngineModel getMalstructuredModel() {
89         final AxEngineModel engineModel = getModel();
90
91         engineModel.setTimestamp(-1);
92         engineModel.setState(AxEngineState.UNDEFINED);
93
94         return engineModel;
95     }
96
97     @Override
98     public AxEngineModel getObservationModel() {
99         final AxEngineModel engineModel = getModel();
100
101         final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
102                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
103         final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
104                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
105
106         engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
107                 new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
108         engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
109                 new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000002"), ""));
110
111         return engineModel;
112     }
113
114     @Override
115     public AxEngineModel getWarningModel() {
116         final AxEngineModel engineModel = getModel();
117
118         final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
119                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
120         final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
121                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
122
123         engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
124                 new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
125         engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
126                 new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
127
128         return engineModel;
129     }
130 }