88import com .cloudinary .utils .ObjectUtils ;
99import org .hamcrest .Matcher ;
1010import org .hamcrest .Matchers ;
11- import org .junit .Before ;
12- import org .junit .BeforeClass ;
13- import org .junit .Rule ;
14- import org .junit .Test ;
11+ import org .junit .*;
1512import org .junit .rules .TestName ;
1613
1714import java .io .IOException ;
18- import java .util .*;
15+ import java .util .Arrays ;
16+ import java .util .Collections ;
17+ import java .util .List ;
18+ import java .util .Map ;
1919
2020import static org .hamcrest .Matchers .*;
2121import static org .junit .Assert .assertThat ;
@@ -26,6 +26,9 @@ abstract public class AbstractStreamingProfilesApiTest extends MockableTest {
2626 private static final String PROFILE_NAME = "api_test_streaming_profile" + SUFFIX ;
2727 protected Api api ;
2828 private static final List <String > PREDEFINED_PROFILES = Arrays .asList ("4k" , "full_hd" , "hd" , "sd" , "full_hd_wifi" , "full_hd_lean" , "hd_lean" );
29+ public static final String UPDATE_PROFILE_NAME = PROFILE_NAME + "_update" ;
30+ public static final String DELETE_PROFILE_NAME = PROFILE_NAME + "_delete" ;
31+ public static final String CREATE_PROFILE_NAME = PROFILE_NAME + "_create" ;
2932
3033 @ BeforeClass
3134 public static void setUpClass () throws IOException {
@@ -48,14 +51,13 @@ public void setUp() {
4851
4952 @ Test
5053 public void testCreate () throws Exception {
51- final String name = PROFILE_NAME + "_create" ;
52- ApiResponse result = api .createStreamingProfile (name , null , Collections .singletonList (ObjectUtils .asMap (
54+ ApiResponse result = api .createStreamingProfile (CREATE_PROFILE_NAME , null , Collections .singletonList (ObjectUtils .asMap (
5355 "transformation" , new Transformation ().crop ("limit" ).width (1200 ).height (1200 ).bitRate ("5m" )
5456 )), ObjectUtils .emptyMap ());
5557
5658 assertTrue (result .containsKey ("data" ));
5759 Map profile = (Map ) result .get ("data" );
58- assertThat (profile , (Matcher ) hasEntry ("name" , (Object ) name ));
60+ assertThat (profile , (Matcher ) hasEntry ("name" , (Object ) CREATE_PROFILE_NAME ));
5961 }
6062
6163 @ Test
@@ -82,39 +84,37 @@ public void testList() throws Exception {
8284 @ Test
8385 public void testDelete () throws Exception {
8486 ApiResponse result ;
85- final String name = PROFILE_NAME + "_delete" ;
8687 try {
87- api .createStreamingProfile (name , null , Collections .singletonList (ObjectUtils .asMap (
88+ api .createStreamingProfile (DELETE_PROFILE_NAME , null , Collections .singletonList (ObjectUtils .asMap (
8889 "transformation" , new Transformation ().crop ("limit" ).width (1200 ).height (1200 ).bitRate ("5m" )
8990 )), ObjectUtils .emptyMap ());
9091 } catch (AlreadyExists ignored ) {
9192 }
9293
93- result = api .deleteStreamingProfile (name );
94+ result = api .deleteStreamingProfile (DELETE_PROFILE_NAME );
9495 assertTrue (result .containsKey ("data" ));
9596 Map profile = (Map ) result .get ("data" );
96- assertThat (profile , (Matcher ) hasEntry ("name" , (Object ) ( name ) ));
97+ assertThat (profile , (Matcher ) hasEntry ("name" , (Object ) DELETE_PROFILE_NAME ));
9798
9899 }
99100
100101 @ Test
101102 public void testUpdate () throws Exception {
102- final String name = PROFILE_NAME + "_update" ;
103103 try {
104- api .createStreamingProfile (name , null , Collections .singletonList (ObjectUtils .asMap (
104+ api .createStreamingProfile (UPDATE_PROFILE_NAME , null , Collections .singletonList (ObjectUtils .asMap (
105105 "transformation" , new Transformation ().crop ("limit" ).width (1200 ).height (1200 ).bitRate ("5m" )
106106 )), ObjectUtils .emptyMap ());
107107 } catch (AlreadyExists ignored ) {
108108 }
109- Map result = api .updateStreamingProfile (name , null , Collections .singletonList (
109+ Map result = api .updateStreamingProfile (UPDATE_PROFILE_NAME , null , Collections .singletonList (
110110 ObjectUtils .asMap ("transformation" ,
111111 new Transformation ().crop ("limit" ).width (800 ).height (800 ).bitRate ("5m" )
112112 )), ObjectUtils .emptyMap ());
113113
114114 assertTrue (result .containsKey ("data" ));
115115 assertThat (result , (Matcher ) hasEntry ("message" , (Object ) "updated" ));
116116 Map profile = (Map ) result .get ("data" );
117- assertThat (profile , (Matcher ) hasEntry ("name" , (Object ) ( name ) ));
117+ assertThat (profile , (Matcher ) hasEntry ("name" , (Object ) UPDATE_PROFILE_NAME ));
118118 assertThat (profile , Matchers .hasEntry (equalTo ("representations" ), (Matcher ) hasItem (hasKey ("transformation" ))));
119119 final Map representation = (Map ) ((List ) profile .get ("representations" )).get (0 );
120120 Map transformation = (Map ) ((List )representation .get ("transformation" )).get (0 );
@@ -125,4 +125,16 @@ public void testUpdate() throws Exception {
125125 (Matcher ) hasEntry ("bit_rate" , "5m" )
126126 ));
127127 }
128+
129+ @ AfterClass
130+ public static void tearDownClass () {
131+ Api api = new Cloudinary ().api ();
132+ try {
133+ api .deleteStreamingProfile (CREATE_PROFILE_NAME );
134+ api .deleteStreamingProfile (DELETE_PROFILE_NAME );
135+ api .deleteStreamingProfile (UPDATE_PROFILE_NAME );
136+ } catch (Exception e ) {
137+ e .printStackTrace ();
138+ }
139+ }
128140}
0 commit comments