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