9e7d99b723eac379e968c021d86ed8c602e0b355
[policy/apex-pdp.git] /
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 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
25 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
26 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
28 import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
29 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
30 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
31 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
32 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
33 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
34 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
35 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats;
36
37 public class DummyTestApexEngineModelCreator implements TestApexModelCreator<AxEngineModel> {
38
39     @Override
40     public AxEngineModel getModel() {
41         final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
42                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
43         final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
44                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
45
46         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
47         schemas.getSchemasMap().put(schema0.getKey(), schema0);
48         schemas.getSchemasMap().put(schema1.getKey(), schema1);
49
50         final AxContextAlbum album0 =
51                 new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema1.getKey());
52
53         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
54         albums.getAlbumsMap().put(album0.getKey(), album0);
55
56         final AxEngineModel engineModel = new AxEngineModel(new AxArtifactKey("AnEngine", "0.0.1"));
57         engineModel.setSchemas(schemas);
58         engineModel.setAlbums(albums);
59         engineModel.setTimestamp(System.currentTimeMillis());
60         engineModel.setState(AxEngineState.EXECUTING);
61         engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
62                 System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
63         engineModel.getKeyInformation().generateKeyInfo(engineModel);
64
65         final AxValidationResult result = new AxValidationResult();
66         engineModel.validate(result);
67
68         return engineModel;
69     }
70
71     @Override
72     public AxEngineModel getInvalidModel() {
73         final AxEngineModel engineModel = getModel();
74
75         engineModel.setTimestamp(System.currentTimeMillis());
76         engineModel.setState(AxEngineState.UNDEFINED);
77         engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
78                 System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
79         engineModel.getKeyInformation().generateKeyInfo(engineModel);
80
81         return engineModel;
82     }
83
84     /**
85      * Get a malstructured model.
86      */
87     public AxEngineModel getMalstructuredModel() {
88         final AxEngineModel engineModel = getModel();
89
90         engineModel.setTimestamp(-1);
91         engineModel.setState(AxEngineState.UNDEFINED);
92
93         return engineModel;
94     }
95
96     @Override
97     public AxEngineModel getObservationModel() {
98         final AxEngineModel engineModel = getModel();
99
100         final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
101                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
102         final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
103                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
104
105         engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
106                 new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
107         engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
108                 new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000002"), ""));
109
110         return engineModel;
111     }
112
113     @Override
114     public AxEngineModel getWarningModel() {
115         final AxEngineModel engineModel = getModel();
116
117         final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
118                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
119         final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
120                 "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
121
122         engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
123                 new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
124         engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
125                 new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
126
127         return engineModel;
128     }
129 }