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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.plugins.event.protocol.xml;
23 import java.util.Random;
26 * @author Liam Fallon (liam.fallon@ericsson.com)
28 public class XMLEventGenerator {
29 private static int nextEventNo = 0;
31 public static String xmlEvents(final int eventCount) {
32 final StringBuilder builder = new StringBuilder();
34 for (int i = 0; i < eventCount; i++) {
38 builder.append(xmlEvent());
41 return builder.toString();
44 public static String xmlEvent() {
45 final Random rand = new Random();
47 final StringBuilder builder = new StringBuilder();
49 int nextEventNo = rand.nextInt(2);
50 final String eventName = (nextEventNo == 0 ? "Event0000" : "Event0100");
51 final int nextMatchCase = rand.nextInt(4);
52 final float nextTestTemperature = rand.nextFloat() * 10000;
54 builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
55 builder.append("<xmlApexEvent xmlns=\"http://www.onap.org/policy/apex-pdp/apexevent\">\n");
57 builder.append(" <name>" + eventName + "</name>\n");
58 builder.append(" <version>0.0.1</version>\n");
59 builder.append(" <nameSpace>org.onap.policy.apex.sample.events</nameSpace>\n");
60 builder.append(" <source>test</source>\n");
61 builder.append(" <target>apex</target>\n");
62 builder.append(" <data>\n");
63 builder.append(" <key>TestSlogan</key>\n");
64 builder.append(" <value>Test slogan for External Event" + (nextEventNo++) + "</value>\n");
65 builder.append(" </data>\n");
66 builder.append(" <data>\n");
67 builder.append(" <key>TestMatchCase</key>\n");
68 builder.append(" <value>" + nextMatchCase + "</value>\n");
69 builder.append(" </data>\n");
70 builder.append(" <data>\n");
71 builder.append(" <key>TestTimestamp</key>\n");
72 builder.append(" <value>" + System.currentTimeMillis() + "</value>\n");
73 builder.append(" </data>\n");
74 builder.append(" <data>\n");
75 builder.append(" <key>TestTemperature</key>\n");
76 builder.append(" <value>" + nextTestTemperature + "</value>\n");
77 builder.append(" </data>\n");
78 builder.append("</xmlApexEvent>");
80 return builder.toString();
83 public static void main(final String[] args) {
84 if (args.length != 1) {
85 System.err.println("usage EventGenerator #events");
91 eventCount = Integer.parseInt(args[0]);
92 } catch (final Exception e) {
93 System.err.println("usage EventGenerator #events");
98 System.out.println(xmlEvents(eventCount));
101 public static int getNextEventNo() {