2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.plugins.event.protocol.xml;
24 import java.util.Random;
28 * The Class XmlEventGenerator.
30 public class XmlEventGenerator {
32 private static int nextEventNo = 0;
37 * @param eventCount the event count
40 public static String xmlEvents(final int eventCount) {
41 final StringBuilder builder = new StringBuilder();
43 for (int i = 0; i < eventCount; i++) {
47 builder.append(xmlEvent());
50 return builder.toString();
58 public static String xmlEvent() {
59 final Random rand = new Random();
61 final StringBuilder builder = new StringBuilder();
63 int nextEventNo = rand.nextInt(2);
64 final String eventName = (nextEventNo == 0 ? "Event0000" : "Event0100");
65 final int nextMatchCase = rand.nextInt(4);
66 final float nextTestTemperature = rand.nextFloat() * 10000;
68 builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
69 builder.append("<xmlApexEvent xmlns=\"http://www.onap.org/policy/apex-pdp/apexevent\">\n");
71 builder.append(" <name>" + eventName + "</name>\n");
72 builder.append(" <version>0.0.1</version>\n");
73 builder.append(" <nameSpace>org.onap.policy.apex.sample.events</nameSpace>\n");
74 builder.append(" <source>test</source>\n");
75 builder.append(" <target>apex</target>\n");
76 builder.append(" <data>\n");
77 builder.append(" <key>TestSlogan</key>\n");
78 builder.append(" <value>Test slogan for External Event" + (nextEventNo++) + "</value>\n");
79 builder.append(" </data>\n");
80 builder.append(" <data>\n");
81 builder.append(" <key>TestMatchCase</key>\n");
82 builder.append(" <value>" + nextMatchCase + "</value>\n");
83 builder.append(" </data>\n");
84 builder.append(" <data>\n");
85 builder.append(" <key>TestTimestamp</key>\n");
86 builder.append(" <value>" + System.currentTimeMillis() + "</value>\n");
87 builder.append(" </data>\n");
88 builder.append(" <data>\n");
89 builder.append(" <key>TestTemperature</key>\n");
90 builder.append(" <value>" + nextTestTemperature + "</value>\n");
91 builder.append(" </data>\n");
92 builder.append("</xmlApexEvent>");
94 return builder.toString();
100 * @param args the arguments
102 public static void main(final String[] args) {
103 if (args.length != 1) {
104 System.err.println("usage EventGenerator #events");
110 eventCount = Integer.parseInt(args[0]);
111 } catch (final Exception e) {
112 System.err.println("usage EventGenerator #events");
117 System.out.println(xmlEvents(eventCount));