3 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
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.*;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
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;
41 public class DR_PubResourceTest extends JerseyTest{
44 protected Application configure() {
45 return new ResourceConfig()
46 .register( DR_PubResource.class )
47 .register( FeedResource.class );
50 private static final String fmt = "%24s: %s%n";
51 String d, un, up, f, p;
54 public void setUp() throws Exception {
63 public void tearDown() throws Exception {
69 /* may conflict with test framework!
71 public void setUp() throws Exception {
75 public void tearDown() throws Exception {
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 );
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 );
101 private DR_Pub addPubByName( String d, String un, String up, String feedName) {
102 DR_Pub dr_pub = new DR_Pub( d, un, up, null, "" );
103 dr_pub.setFeedName(feedName);
104 Entity<DR_Pub> reqEntity2 = Entity.entity( dr_pub, MediaType.APPLICATION_JSON);
105 Response resp = target( "dr_pubs").request().post( reqEntity2, Response.class);
106 System.out.println( "POST dr_pubs resp=" + resp.getStatus() );
107 assertTrue( resp.getStatus() == 201 );
108 dr_pub = resp.readEntity( DR_Pub.class );
114 public void GetTest() {
115 Response resp = target( "dr_pubs").request().get( Response.class );
116 System.out.println( "GET dr_pubs resp=" + resp.getStatus() );
118 assertTrue( resp.getStatus() == 200 );
122 public void PostTest() {
124 Feed feed = addFeed( "pubPostTest", "post unit test" );
125 System.out.println( "fpubPostTest: feedId=" + feed.getFeedId());
132 DR_Pub dr_pub = addPub( d, un, up, feed.getFeedId() );
136 public void PostTestByName() {
138 Feed feed = addFeed( "pubPostTest2", "post unit test" );
139 System.out.println( "fpubPostTest: feedId=" + feed.getFeedId());
146 DR_Pub dr_pub = addPubByName( d, un, up, "pubPostTest2" );
150 public void PutTest() {
152 Feed feed = addFeed( "pubPutTest", "put unit test");
158 DR_Pub dr_pub = addPub( d, un, up, feed.getFeedId() );
160 dr_pub.setUserpwd("newSecret");
161 Entity<DR_Pub> reqEntity2 = Entity.entity( dr_pub, MediaType.APPLICATION_JSON);
162 Response resp = target( "dr_pubs")
163 .path( dr_pub.getPubId() )
165 .put( reqEntity2, Response.class);
166 System.out.println( "PUT dr_pubs resp=" + resp.getStatus() );
167 assertTrue( resp.getStatus() == 200 );