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 org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
26 import static org.junit.Assert.*;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
34 import org.glassfish.jersey.test.JerseyTest;
35 import org.glassfish.jersey.server.ResourceConfig;
36 import javax.ws.rs.client.Entity;
37 import javax.ws.rs.core.Application;
38 import javax.ws.rs.core.Response;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.Path;
41 import javax.ws.rs.GET;
43 public class DR_SubResourceTest extends JerseyTest{
45 static DmaapObjectFactory factory = new DmaapObjectFactory();
48 protected Application configure() {
49 return new ResourceConfig()
50 .register( DR_SubResource.class )
51 .register( FeedResource.class )
52 .register( DcaeLocationResource.class )
53 .register( DmaapResource.class );
56 String d, un, up, f, p;
59 public void preTest() throws Exception {
62 Dmaap dmaap = factory.genDmaap();
63 Entity<Dmaap> reqEntity = Entity.entity( dmaap, MediaType.APPLICATION_JSON );
64 Response resp = target( "dmaap").request().post( reqEntity, Response.class );
65 System.out.println( resp.getStatus() );
66 assertTrue( resp.getStatus() == 200 );
67 }catch (Exception e ) {
70 DcaeLocation loc = factory.genDcaeLocation( "central" );
71 Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
72 Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
73 System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ));
74 if ( resp.getStatus() != 409 ) {
75 assertTrue( resp.getStatus() == 201 );
77 } catch (Exception e ) {
84 public void setUp() throws Exception {
93 public void tearDown() throws Exception {
99 /* may conflict with test framework!
101 public void setUp() throws Exception {
105 public void tearDown() throws Exception {
109 private Feed addFeed( String name, String desc ) {
110 Feed feed = new Feed( name, "1.0", desc, "dgl", "unrestricted" );
111 Entity<Feed> reqEntity = Entity.entity( feed, MediaType.APPLICATION_JSON );
112 Response resp = target( "feeds").request().post( reqEntity, Response.class );
113 int rc = resp.getStatus();
114 System.out.println( "POST feed resp=" + rc );
115 assertTrue( rc == 200 || rc == 409 );
116 feed = resp.readEntity( Feed.class );
120 private DR_Sub addSub( String d, String un, String up, String feedId ) {
121 DR_Sub dr_sub = new DR_Sub( d, un, up, feedId,
122 "https://subscriber.onap.org/foo", "https://dr-prov/sublog", true );
124 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
125 Response resp = target( "dr_subs").request().post( reqEntity2, Response.class);
126 System.out.println( "POST dr_subs resp=" + resp.getStatus() );
127 assertTrue( resp.getStatus() == 201 );
128 dr_sub = resp.readEntity( DR_Sub.class );
132 private DR_Sub addSubByName( String d, String un, String up, String feedName ) {
133 DR_Sub dr_sub = new DR_Sub( d, un, up, null,
134 "https://subscriber.onap.org/foo", "https://dr-prov/sublog", true );
136 dr_sub.setFeedName(feedName);
138 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
139 Response resp = target( "dr_subs").request().post( reqEntity2, Response.class);
140 System.out.println( "POST dr_subs resp=" + resp.getStatus() );
141 assertTrue( resp.getStatus() == 201 );
142 dr_sub = resp.readEntity( DR_Sub.class );
148 public void GetTest() {
149 Response resp = target( "dr_subs").request().get( Response.class );
150 System.out.println( "GET dr_subs resp=" + resp.getStatus() );
152 assertTrue( resp.getStatus() == 200 );
156 public void PostTest() {
158 Feed feed = addFeed( "subPostTest", "post unit test" );
159 System.out.println( "subPostTest: feedId=" + feed.getFeedId());
166 DR_Sub dr_pub = addSub( d, un, up, feed.getFeedId() );
170 public void PostTestByName() {
172 Feed feed = addFeed( "subPostTest2", "post unit test" );
173 System.out.println( "subPostTest2: feedId=" + feed.getFeedId());
180 DR_Sub dr_pub = addSubByName( d, un, up, feed.getFeedName() );
184 public void PutTest() {
186 Feed feed = addFeed( "subPutTest", "put unit test");
192 DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
194 dr_sub.setUserpwd("newSecret");
195 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
196 Response resp = target( "dr_subs")
197 .path( dr_sub.getSubId() )
199 .put( reqEntity2, Response.class);
200 System.out.println( "PUT dr_subs resp=" + resp.getStatus() );
201 assertTrue( resp.getStatus() == 200 );
205 * TODO: figure out how to check delete() response
207 public void DelTest() {
209 Feed feed = addFeed( "subDelTest", "del unit test");
215 DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
217 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
218 Response resp = target( "dr_subs")
219 .path( dr_sub.getSubId() )
222 System.out.println( "DEL dr_subs resp=" + resp.getStatus() );
223 assertTrue( resp.getStatus() == 200 );