48d1016d4850d3bfeba8fe2455eba499eaf16b10
[dmaap/dbcapi.git] / src / test / java / org / onap / dmaap / dbcapi / resources / DR_SubResourceTest.java
1
2 /*-
3  * ============LICENSE_START=======================================================
4  * org.onap.dmaap
5  * ================================================================================
6  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.dmaap.dbcapi.resources;
22 import org.onap.dmaap.dbcapi.model.*;
23 import org.onap.dmaap.dbcapi.service.*;
24 import static org.junit.Assert.*;
25
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import java.util.*;
30 import java.sql.*;
31
32 import org.glassfish.jersey.test.JerseyTest;
33 import org.glassfish.jersey.server.ResourceConfig;
34 import javax.ws.rs.client.Entity;
35 import javax.ws.rs.core.Application;
36 import javax.ws.rs.core.Response;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.Path;
39 import javax.ws.rs.GET;
40
41 public class DR_SubResourceTest extends JerseyTest{
42
43         @Override
44         protected Application configure() {
45                 return new ResourceConfig()
46                                 .register( DR_SubResource.class )
47                                 .register( FeedResource.class );
48         }
49
50         private static final String  fmt = "%24s: %s%n";
51         String d, un, up, f, p;
52 /*
53         @Before
54         public void setUp() throws Exception {
55                 d = "central-onap";
56                 un = "user1";
57                 up = "secretW0rd";
58                 f = "234";
59                 p = "678";
60         }
61
62         @After
63         public void tearDown() throws Exception {
64         }
65 */
66
67
68
69 /*  may conflict with test framework! 
70         @Before
71         public void setUp() throws Exception {
72         }
73
74         @After
75         public void tearDown() throws Exception {
76         }
77 */
78
79         private Feed addFeed( String name, String desc ) {
80                 Feed feed = new Feed( name, "1.0", desc, "dgl", "unrestricted" );
81                 Entity<Feed> reqEntity = Entity.entity( feed, MediaType.APPLICATION_JSON );
82                 Response resp = target( "feeds").request().post( reqEntity, Response.class );
83                 int rc = resp.getStatus();
84                 System.out.println( "POST feed resp=" + rc );
85                 assertTrue( rc == 200 || rc == 409 );
86                 feed = resp.readEntity( Feed.class );
87                 return feed;
88         }
89         
90         private DR_Sub addSub( String d, String un, String up, String feedId ) {
91                 DR_Sub dr_sub = new DR_Sub( d, un, up, feedId, 
92                                 "https://subscriber.onap.org/foo", "https://dr-prov/sublog", true );
93
94                 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
95                 Response resp = target( "dr_subs").request().post( reqEntity2, Response.class);
96                 System.out.println( "POST dr_subs resp=" + resp.getStatus() );
97                 assertTrue( resp.getStatus() == 201 );
98                 dr_sub = resp.readEntity( DR_Sub.class );
99                 
100                 return dr_sub;
101         }
102         
103         @Test
104         public void GetTest() {
105                 Response resp = target( "dr_subs").request().get( Response.class );
106                 System.out.println( "GET dr_subs resp=" + resp.getStatus() );
107
108                 assertTrue( resp.getStatus() == 200 );
109         }
110         
111         @Test
112         public void PostTest() {
113
114                 Feed feed = addFeed( "subPostTest", "post unit test" );
115                 System.out.println( "subPostTest: feedId=" + feed.getFeedId());
116                 
117                 String d, un, up;
118                 d = "central-onap";
119                 un = "user1";
120                 up = "secretW0rd";
121
122                 DR_Sub dr_pub = addSub( d, un, up, feed.getFeedId() );
123         }
124
125         @Test
126         public void PutTest() {
127
128                 Feed feed = addFeed( "subPutTest", "put unit test");
129                 String d, un, up;
130                 d = "central-onap";
131                 un = "user1";
132                 up = "secretW0rd";
133
134                 DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
135                 
136                 dr_sub.setUserpwd("newSecret");
137                 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
138                 Response resp = target( "dr_subs")
139                                 .path( dr_sub.getSubId() )
140                                 .request()
141                                 .put( reqEntity2, Response.class);
142                 System.out.println( "PUT dr_subs resp=" + resp.getStatus() );
143                 assertTrue( resp.getStatus() == 200 );
144         }
145 /*
146  * TODO: figure out how to check delete() response
147         @Test
148         public void DelTest() {
149
150                 Feed feed = addFeed( "subDelTest", "del unit test");
151                 String d, un, up;
152                 d = "central-onap";
153                 un = "user1";
154                 up = "secretW0rd";
155
156                 DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
157                 
158                 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
159                 Response resp = target( "dr_subs")
160                                 .path( dr_sub.getSubId() )
161                                 .request()
162                                 .delete();
163                 System.out.println( "DEL dr_subs resp=" + resp.getStatus() );
164                 assertTrue( resp.getStatus() == 200 );
165         }
166 */
167
168 }
169
170