Improve support for http to MR
[dmaap/dbcapi.git] / src / test / java / org / onap / dmaap / dbcapi / testframework / DmaapObjectFactory.java
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2018 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 package org.onap.dmaap.dbcapi.testframework;
21
22 import org.onap.dmaap.dbcapi.model.DR_Node;
23 import org.onap.dmaap.dbcapi.model.DR_Sub;
24 import org.onap.dmaap.dbcapi.model.DcaeLocation;
25 import org.onap.dmaap.dbcapi.model.Dmaap;
26 import org.onap.dmaap.dbcapi.model.FqtnType;
27 import org.onap.dmaap.dbcapi.model.MR_Client;
28 import org.onap.dmaap.dbcapi.model.MR_Cluster;
29 import org.onap.dmaap.dbcapi.model.Topic;
30 import org.onap.dmaap.dbcapi.util.RandomInteger;
31
32 import static org.junit.Assert.*;
33
34 import java.lang.reflect.Constructor;
35 import java.lang.reflect.InvocationTargetException;
36 import java.lang.reflect.Method;
37 import java.lang.reflect.Type;
38
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42
43 import static java.lang.System.out;
44 import static java.lang.System.err;
45
46 public class DmaapObjectFactory {
47
48         /*
49          * we use localhost for most references so that connection attempts will resolve and not retry
50          * but still we expect that requests will fail.
51          */
52         private static final String  fmt = "%24s: %s%n";
53         private static final String     dmaap_name = "onap-ut";
54         private static final String dmaap_ver = "1";
55         private static final String dmaap_topic_root = "org.onap.dmaap";
56         private static final String dmaap_dr = "https://localhost:8443";
57         private static final String dmaap_log_url = "http://localhost:8080/log";
58         private static final String dmaap_mm_topic = "org.onap.dmaap.dcae.MM_AGENT_TOPIC";
59         private static final String central_loc = "SanFrancisco";
60         private static final String central_layer = "central-cloud";
61         private static final String central_clli = "SFCAL19240";
62         private static final String central_zone = "osaz01";
63         private static final String central_subnet = "10.10.10.0/24";
64         private static final String central_cluster_fqdn = "localhost";
65         private static final String pub_role = "org.onap.vnfapp.publisher";
66         private static final String sub_role = "org.onap.vnfapp.subscriber";
67         private static final String edge_loc = "Atlanta";
68         private static final String edge_layer = "edge-cloud";
69         private static final String edge_clli = "ATLGA10245";
70         private static final String edge_zone = "osaz02";
71         private static final String edge_subnet = "10.10.20.0/24";
72         private static final String edge_cluster_fqdn = "localhost";
73         private static final String[]hosts = { "host1", "host2", "host3" };
74         private static final String port = "3904";
75         private static final String prot = "http";
76
77         public Dmaap genDmaap() {
78                 return new Dmaap( dmaap_ver, dmaap_topic_root, dmaap_name, dmaap_dr, dmaap_log_url, dmaap_mm_topic, "nk", "ako" );
79         }
80
81         public DcaeLocation genDcaeLocation( String layer ) {
82                 if ( layer.contains( "edge" ) ) {
83                         return new DcaeLocation( edge_clli, edge_layer, edge_loc, edge_zone, edge_subnet );
84                 }
85                 return new DcaeLocation( central_clli, central_layer, central_loc, central_zone, central_subnet );
86         }
87
88
89         public MR_Cluster genMR_Cluster( String layer ) {
90                 if ( layer.contains( "edge" ) ) {
91                         return new MR_Cluster( edge_loc, edge_cluster_fqdn,  prot, port );
92                 }
93                 return new MR_Cluster( central_loc, central_cluster_fqdn, prot, port );
94         }
95
96         public Topic genSimpleTopic( String tname ) {
97                 Topic t = new Topic();
98                 t.setTopicName( tname );
99         t.setFqtnStyle( FqtnType.Validator("none") );
100         t.setTopicDescription( "a simple Topic named " + tname );
101         t.setOwner( "ut");
102                 return t;
103         }
104
105         public MR_Client genMR_Client( String l, String f, String r, String[] a ) {
106                 if ( l.contains( "edge" ) ) {
107                         return new MR_Client( edge_loc, f, r, a );
108                 }
109                 return new MR_Client( central_loc, f, r, a );
110         }
111
112         public MR_Client genPublisher( String layer, String fqtn ) {
113                 String[] actions = { "pub", "view" };
114                 return genMR_Client( layer, fqtn, pub_role, actions );
115         }
116         public MR_Client genSubscriber( String layer, String fqtn ) {
117                 String[] actions = { "sub", "view" };
118                 return genMR_Client( layer, fqtn, sub_role, actions );
119         }
120
121         public DR_Sub genDrSub( String l, String feed ) {
122         String un = "user1";
123         String up = "secretW0rd";
124         String du = "sub.server.onap.org:8443/deliver/here";
125         String lu = "https://drps.onap.org:8443/sublog/123";
126         boolean u100 = true;
127
128                 if ( l.contains( "edge" ) ) {
129                         return new DR_Sub( edge_loc, un, up, feed, du, lu, u100 );
130                 }
131                 return new DR_Sub( central_loc, un, up, feed, du, lu, u100 );
132         }
133
134         public DR_Node genDR_Node( String l ) {
135         String version = "1.0.1";
136                 RandomInteger ri = new RandomInteger( 1000 );
137                 int i = ri.next();
138                 String fqdn = String.format( "drns%d.onap.org", i );
139                 String host = String.format( "host%d.onap.org", i );
140
141                 if ( l.contains( "edge" ) ) {
142                         return new DR_Node( fqdn, edge_loc, host, version );
143                 }
144                 return new DR_Node( fqdn, central_loc, host, version );
145         }
146                                 
147
148 }