1+ package com .jaspersoft .jasperserver .jaxrs .client .apiadapters .attributes ;
2+
3+ import com .jaspersoft .jasperserver .dto .authority .ClientUserAttribute ;
4+ import com .jaspersoft .jasperserver .dto .authority .hypermedia .HypermediaAttribute ;
5+ import com .jaspersoft .jasperserver .dto .authority .hypermedia .HypermediaAttributesListWrapper ;
6+ import com .jaspersoft .jasperserver .jaxrs .client .RestClientTestUtil ;
7+ import com .jaspersoft .jasperserver .jaxrs .client .core .operationresult .NullEntityOperationResult ;
8+ import com .jaspersoft .jasperserver .jaxrs .client .core .operationresult .OperationResult ;
9+ import java .util .List ;
10+ import javax .ws .rs .core .Response ;
11+ import org .testng .annotations .AfterClass ;
12+ import org .testng .annotations .BeforeClass ;
13+ import org .testng .annotations .Test ;
14+
15+ import static java .util .Arrays .asList ;
16+ import static org .hamcrest .core .IsInstanceOf .instanceOf ;
17+ import static org .junit .Assert .assertTrue ;
18+ import static org .testng .AssertJUnit .assertEquals ;
19+ import static org .testng .AssertJUnit .assertNotNull ;
20+
21+ public class OrganizationBatchAttributesServiceIT extends RestClientTestUtil {
22+
23+ private HypermediaAttributesListWrapper serverAttributes ;
24+ private String orgName ;
25+
26+ @ BeforeClass
27+ public void before () {
28+ serverAttributes = new HypermediaAttributesListWrapper ();
29+ serverAttributes .setProfileAttributes (asList (
30+ new HypermediaAttribute (new ClientUserAttribute ().setName ("test_max_threads" ).setValue ("512" )),
31+ new HypermediaAttribute (new ClientUserAttribute ().setName ("test_admin_cell_phone" ).setValue ("03" ))));
32+ orgName = "myOrg1" ;
33+ initClient ();
34+ initSession ();
35+ }
36+
37+ @ Test
38+ public void should_create_attributes () {
39+
40+ OperationResult <HypermediaAttributesListWrapper > attributes = session
41+ .attributesService ()
42+ .forOrganization (orgName )
43+ .attributes (asList (serverAttributes .getProfileAttributes ().get (0 ).getName (),
44+ serverAttributes .getProfileAttributes ().get (1 ).getName ()))
45+ .createOrUpdate (serverAttributes );
46+
47+ assertNotNull (attributes );
48+
49+ }
50+
51+ @ Test (dependsOnMethods = "should_create_attributes" )
52+ public void should_return_server_attributes () {
53+ List <HypermediaAttribute > attributes = session
54+ .attributesService ()
55+ .forOrganization (orgName )
56+ .allAttributes ()
57+ .get ()
58+ .getEntity ()
59+ .getProfileAttributes ();
60+
61+ assertTrue (attributes .size () >= 2 );
62+ }
63+
64+ @ Test (dependsOnMethods = "should_create_attributes" )
65+ public void should_return_server_attributes_with_permissions () {
66+ List <HypermediaAttribute > attributes = session
67+ .attributesService ()
68+ .forOrganization (orgName )
69+ .allAttributes ()
70+ .setIncludePermissions (true )
71+ .get ()
72+ .getEntity ()
73+ .getProfileAttributes ();
74+
75+ assertTrue (attributes .size () >= 2 );
76+ assertTrue (attributes .get (0 ).getEmbedded () != null );
77+ }
78+
79+ @ Test (dependsOnMethods = "should_return_server_attributes_with_permissions" )
80+ public void should_return_specified_server_attributes () {
81+ List <HypermediaAttribute > attributes = session
82+ .attributesService ()
83+ .forOrganization (orgName )
84+ .attributes (asList (serverAttributes .getProfileAttributes ().get (0 ).getName (),
85+ serverAttributes .getProfileAttributes ().get (1 ).getName ()))
86+ .get ()
87+ .getEntity ()
88+ .getProfileAttributes ();
89+
90+ assertTrue (attributes .size () >= 2 );
91+ }
92+
93+
94+
95+ @ Test (dependsOnMethods = "should_return_specified_server_attributes" )
96+ public void should_return_specified_server_attributes_with_permissions () {
97+ List <HypermediaAttribute > attributes = session
98+ .attributesService ()
99+ .forOrganization (orgName )
100+ .attributes (asList (serverAttributes .getProfileAttributes ().get (0 ).getName (),
101+ serverAttributes .getProfileAttributes ().get (1 ).getName ()))
102+ .setIncludePermissions (true )
103+ .get ()
104+ .getEntity ()
105+ .getProfileAttributes ();
106+
107+ assertTrue (attributes .size () >= 2 );
108+ assertTrue (attributes .get (0 ).getEmbedded () != null );
109+ }
110+
111+ @ Test (dependsOnMethods = "should_return_specified_server_attributes_with_permissions" )
112+ public void should_delete_specified_server_attributes () {
113+ OperationResult <HypermediaAttributesListWrapper > operationResult = session
114+ .attributesService ()
115+ .forOrganization (orgName )
116+ .attributes (asList (serverAttributes .getProfileAttributes ().get (0 ).getName (),
117+ serverAttributes .getProfileAttributes ().get (1 ).getName ()))
118+ .delete ();
119+
120+ assertTrue (instanceOf (NullEntityOperationResult .class ).matches (operationResult ));
121+ assertEquals (Response .Status .NO_CONTENT .getStatusCode (), operationResult .getResponse ().getStatus ());
122+ }
123+
124+
125+ @ AfterClass
126+ public void after () {
127+ session .logout ();
128+ session = null ;
129+ }
130+ }
0 commit comments