42c8014b119906f06f4428669fe3cd246305f7ca
[dmaap/dbcapi.git] / src / test / java / org / onap / dmaap / dbcapi / resources / DR_PubResourceTest.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_PubResourceTest extends JerseyTest{
42
43         @Override
44         protected Application configure() {
45                 return new ResourceConfig()
46                                 .register( DR_PubResource.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_Pub addPub( String d, String un, String up, String feedId ) {
91                 DR_Pub dr_pub = new DR_Pub( d, un, up, feedId, "" );
92                 Entity<DR_Pub> reqEntity2 = Entity.entity( dr_pub, MediaType.APPLICATION_JSON);
93                 Response resp = target( "dr_pubs").request().post( reqEntity2, Response.class);
94                 System.out.println( "POST dr_pubs resp=" + resp.getStatus() );
95                 assertTrue( resp.getStatus() == 201 );
96                 dr_pub = resp.readEntity( DR_Pub.class );
97                 
98                 return dr_pub;
99         }
100         
101         @Test
102         public void GetTest() {
103                 Response resp = target( "dr_pubs").request().get( Response.class );
104                 System.out.println( "GET dr_pubs resp=" + resp.getStatus() );
105
106                 assertTrue( resp.getStatus() == 200 );
107         }
108         
109         @Test
110         public void PostTest() {
111
112                 Feed feed = addFeed( "pubPostTest", "post unit test" );
113                 System.out.println( "fpubPostTest: feedId=" + feed.getFeedId());
114                 
115                 String d, un, up;
116                 d = "central-onap";
117                 un = "user1";
118                 up = "secretW0rd";
119
120                 DR_Pub dr_pub = addPub( d, un, up, feed.getFeedId() );
121         }
122
123         @Test
124         public void PutTest() {
125
126                 Feed feed = addFeed( "pubPutTest", "put unit test");
127                 String d, un, up;
128                 d = "central-onap";
129                 un = "user1";
130                 up = "secretW0rd";
131
132                 DR_Pub dr_pub = addPub( d, un, up, feed.getFeedId() );
133                 
134                 dr_pub.setUserpwd("newSecret");
135                 Entity<DR_Pub> reqEntity2 = Entity.entity( dr_pub, MediaType.APPLICATION_JSON);
136                 Response resp = target( "dr_pubs")
137                                 .path( dr_pub.getPubId() )
138                                 .request()
139                                 .put( reqEntity2, Response.class);
140                 System.out.println( "PUT dr_pubs resp=" + resp.getStatus() );
141                 assertTrue( resp.getStatus() == 200 );
142         }
143                 
144
145
146 }
147
148