re base code
[sdc.git] / common / onap-sdc-artifact-generator-lib / onap-sdc-artifact-generator-core / src / main / java / org / onap / sdc / generator / MockArtifactGenerator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.generator;
22
23 import org.onap.sdc.generator.data.*;
24 import org.onap.sdc.generator.intf.ArtifactGenerator;
25 import org.onap.sdc.generator.intf.Generator;
26
27 import java.util.Date;
28 import java.util.List;
29 import java.util.Map;
30
31 @Generator(artifactType = ArtifactType.OTHER)
32 public class MockArtifactGenerator implements ArtifactGenerator {
33
34   @Override
35   public GenerationData generateArtifact(List<Artifact> input,
36                                          Map<String, String> additionalParams) {
37     final GenerationData data = new GenerationData();
38
39     String staticArtifactName = "MOCK_Generator-Static-Artifact.xml";
40     String staticArtifactLabel = "MOCK-Generator-Static-Artifact";
41     final String dynamicArtifactName = "MOCK_Generator-Dynamic-Artifact.xml";
42     final String dynamicArtifactLabel = "MOCK-Generator-Dynamic-Artifact";
43     String staticArtifact = getStaticArtifact();
44     String dynamicArtifact = getDynamicArtifact();
45
46     Artifact staticArtifactModel = new Artifact(ArtifactType.OTHER.name(), GroupType.OTHER.name(),
47         GeneratorUtil.checkSum(staticArtifact.getBytes()),
48         GeneratorUtil.encode(staticArtifact.getBytes()));
49     staticArtifactModel.setName(staticArtifactName);
50     staticArtifactModel.setLabel(staticArtifactLabel);
51     staticArtifactModel.setDescription("Mock Generator");
52
53     Artifact dynamicArtifactModel = new Artifact(ArtifactType.OTHER.name(), GroupType.OTHER.name(),
54         GeneratorUtil.checkSum(dynamicArtifact.getBytes()),
55         GeneratorUtil.encode(dynamicArtifact.getBytes()));
56     dynamicArtifactModel.setName(dynamicArtifactName);
57     dynamicArtifactModel.setLabel(dynamicArtifactLabel);
58     dynamicArtifactModel.setDescription("Mock Generator");
59
60     data.add(staticArtifactModel);
61     data.add(dynamicArtifactModel);
62
63     return data;
64
65   }
66
67   private String getStaticArtifact() {
68     return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><theObj><name>Hi I'm Static</name></theObj>";
69   }
70
71   private String getDynamicArtifact() {
72     return
73         "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><theObj><name>Hi I'm Static</name><timestamp>"
74             + new Date() + "</timestamp></theObj>";
75   }
76
77 }