2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dmaap.dbcapi.resources;
22 import static org.junit.Assert.assertTrue;
24 import javax.ws.rs.client.Entity;
25 import javax.ws.rs.core.Application;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28 import org.glassfish.jersey.server.ResourceConfig;
29 import org.glassfish.jersey.test.JerseyTest;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.dmaap.dbcapi.model.DcaeLocation;
33 import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
36 public class DcaeLocationResourceTest extends JerseyTest {
38 static DmaapObjectFactory factory = new DmaapObjectFactory();
41 protected Application configure() {
42 return new ResourceConfig( DcaeLocationResource.class );
46 public static void setUpClass(){
47 System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
51 public void GetTest() {
52 Response resp = target( "dcaeLocations").request().get( Response.class );
53 System.out.println( "GET feed resp=" + resp.getStatus() );
55 assertTrue( resp.getStatus() == 200 );
58 public void PostTest() {
59 DcaeLocation loc = factory.genDcaeLocation( "central" );
60 Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
61 Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
62 System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
63 if ( resp.getStatus() != 409 ) {
64 assertTrue( resp.getStatus() == 201 );
67 resp = target( "dcaeLocations").
68 path( loc.getDcaeLocationName()).request().get( Response.class );
69 System.out.println( "GET feed resp=" + resp.getStatus() );
71 assertTrue( resp.getStatus() == 200 );
75 public void PutTest() {
76 DcaeLocation loc = factory.genDcaeLocation( "edge" );
77 Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
78 Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
79 System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
80 if ( resp.getStatus() != 409 ) {
81 assertTrue( resp.getStatus() == 201 );
85 loc.setClli("ATLCTYNJ9999");
86 reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
87 resp = target( "dcaeLocations").
88 path( loc.getDcaeLocationName()).request().put( reqEntity, Response.class );
89 System.out.println( "PUT dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
90 assertTrue( resp.getStatus() == 201 );
95 public void DelTest() {
96 DcaeLocation loc = factory.genDcaeLocation( "edge" );
97 Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
98 Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
99 System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
100 if ( resp.getStatus() != 409 ) {
101 assertTrue( resp.getStatus() == 201 );
104 resp = target( "dcaeLocations").
105 path( loc.getDcaeLocationName()).request().delete( Response.class );
106 System.out.println( "DELETE dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
107 assertTrue( resp.getStatus() == 204 );