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_SubResourceTest extends JerseyTest{
44 protected Application configure() {
45 return new ResourceConfig()
46 .register( DR_SubResource.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_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 );
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 );
104 public void GetTest() {
105 Response resp = target( "dr_subs").request().get( Response.class );
106 System.out.println( "GET dr_subs resp=" + resp.getStatus() );
108 assertTrue( resp.getStatus() == 200 );
112 public void PostTest() {
114 Feed feed = addFeed( "subPostTest", "post unit test" );
115 System.out.println( "subPostTest: feedId=" + feed.getFeedId());
122 DR_Sub dr_pub = addSub( d, un, up, feed.getFeedId() );
126 public void PutTest() {
128 Feed feed = addFeed( "subPutTest", "put unit test");
134 DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
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() )
141 .put( reqEntity2, Response.class);
142 System.out.println( "PUT dr_subs resp=" + resp.getStatus() );
143 assertTrue( resp.getStatus() == 200 );
146 * TODO: figure out how to check delete() response
148 public void DelTest() {
150 Feed feed = addFeed( "subDelTest", "del unit test");
156 DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
158 Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
159 Response resp = target( "dr_subs")
160 .path( dr_sub.getSubId() )
163 System.out.println( "DEL dr_subs resp=" + resp.getStatus() );
164 assertTrue( resp.getStatus() == 200 );