3535public class SamlInitiateSingleSignOnAttributesTests extends ESTestCase {
3636
3737 public void testConstructors () throws Exception {
38- // Test default constructor
39- final SamlInitiateSingleSignOnAttributes attributes1 = new SamlInitiateSingleSignOnAttributes ();
38+ final SamlInitiateSingleSignOnAttributes attributes1 = new SamlInitiateSingleSignOnAttributes (Collections .emptyMap ());
4039 assertThat (attributes1 .getAttributes (), Matchers .anEmptyMap ());
4140
42- // Test a second instance is also empty (not holding state)
43- final SamlInitiateSingleSignOnAttributes attributes2 = new SamlInitiateSingleSignOnAttributes ();
44- assertThat (attributes2 .getAttributes (), Matchers .anEmptyMap ());
45-
4641 // Test adding attributes
4742 Map <String , List <String >> attributeMap = new HashMap <>();
4843 attributeMap .put ("key1" , Collections .singletonList ("value1" ));
49- final SamlInitiateSingleSignOnAttributes attributes3 = new SamlInitiateSingleSignOnAttributes ();
50- attributes3 .setAttributes (attributeMap );
44+ final SamlInitiateSingleSignOnAttributes attributes3 = new SamlInitiateSingleSignOnAttributes (attributeMap );
5145 assertThat (attributes3 .getAttributes ().size (), equalTo (1 ));
5246 }
5347
5448 public void testEmptyAttributes () throws Exception {
55- final SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes ();
49+ final SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes (Collections . emptyMap () );
5650
5751 // Test toXContent
5852 XContentBuilder builder = XContentFactory .jsonBuilder ();
@@ -70,12 +64,10 @@ public void testEmptyAttributes() throws Exception {
7064 }
7165
7266 public void testWithAttributes () throws Exception {
73- final SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes ();
74-
7567 Map <String , List <String >> attributeMap = new HashMap <>();
7668 attributeMap .put ("key1" , Arrays .asList ("value1" , "value2" ));
7769 attributeMap .put ("key2" , Collections .singletonList ("value3" ));
78- attributes . setAttributes (attributeMap );
70+ final SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes (attributeMap );
7971
8072 // Test getAttributes
8173 Map <String , List <String >> returnedAttributes = attributes .getAttributes ();
@@ -121,38 +113,28 @@ public void testWithAttributes() throws Exception {
121113 }
122114
123115 public void testToString () {
124- final SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes ();
125116 Map <String , List <String >> attributeMap = new HashMap <>();
126117 attributeMap .put ("key1" , Arrays .asList ("value1" , "value2" ));
127- attributes . setAttributes (attributeMap );
118+ final SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes (attributeMap );
128119
129120 String toString = attributes .toString ();
130121 assertThat (toString , containsString ("SamlInitiateSingleSignOnAttributes" ));
131122 assertThat (toString , containsString ("key1" ));
132123 assertThat (toString , containsString ("value1" ));
133124 assertThat (toString , containsString ("value2" ));
134125
135- // Add another attribute
136- attributeMap .put ("key2" , Collections .singletonList ("value3" ));
137- attributes .setAttributes (attributeMap );
138-
139- toString = attributes .toString ();
140- assertThat (toString , containsString ("key2" ));
141- assertThat (toString , containsString ("value3" ));
142-
143126 // Test empty attributes
144- final SamlInitiateSingleSignOnAttributes emptyAttributes = new SamlInitiateSingleSignOnAttributes ();
127+ final SamlInitiateSingleSignOnAttributes emptyAttributes = new SamlInitiateSingleSignOnAttributes (Collections . emptyMap () );
145128 toString = emptyAttributes .toString ();
146129 assertThat (toString , containsString ("SamlInitiateSingleSignOnAttributes" ));
147130 assertThat (toString , containsString ("attributes={}" ));
148131 }
149132
150133 public void testValidation () throws Exception {
151134 // Test validation with empty key
152- SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes ();
153135 Map <String , List <String >> attributeMap = new HashMap <>();
154136 attributeMap .put ("" , Arrays .asList ("value1" , "value2" ));
155- attributes . setAttributes (attributeMap );
137+ SamlInitiateSingleSignOnAttributes attributes = new SamlInitiateSingleSignOnAttributes (attributeMap );
156138
157139 ActionRequestValidationException validationException = attributes .validate ();
158140 assertNotNull (validationException );
@@ -161,7 +143,7 @@ public void testValidation() throws Exception {
161143 // Test validation with null key
162144 attributeMap = new HashMap <>();
163145 attributeMap .put (null , Collections .singletonList ("value" ));
164- attributes . setAttributes (attributeMap );
146+ attributes = new SamlInitiateSingleSignOnAttributes (attributeMap );
165147
166148 validationException = attributes .validate ();
167149 assertNotNull (validationException );
@@ -173,19 +155,17 @@ public void testEqualsAndHashCode() {
173155 attributeMap1 .put ("key1" , Arrays .asList ("value1" , "value2" ));
174156 attributeMap1 .put ("key2" , Collections .singletonList ("value3" ));
175157
176- SamlInitiateSingleSignOnAttributes attributes1 = new SamlInitiateSingleSignOnAttributes ();
177- attributes1 .setAttributes (attributeMap1 );
158+ SamlInitiateSingleSignOnAttributes attributes1 = new SamlInitiateSingleSignOnAttributes (attributeMap1 );
178159
179160 Map <String , List <String >> attributeMap2 = new HashMap <>();
180161 attributeMap2 .put ("key1" , Arrays .asList ("value1" , "value2" ));
181162 attributeMap2 .put ("key2" , Collections .singletonList ("value3" ));
182163
183- SamlInitiateSingleSignOnAttributes attributes2 = new SamlInitiateSingleSignOnAttributes ();
184- attributes2 .setAttributes (attributeMap2 );
164+ SamlInitiateSingleSignOnAttributes attributes2 = new SamlInitiateSingleSignOnAttributes (attributeMap2 );
185165
186166 // Test equals
187- assertTrue (attributes1 . equals ( attributes2 ) );
188- assertTrue (attributes2 . equals ( attributes1 ) );
167+ assertEquals (attributes1 , attributes2 );
168+ assertEquals (attributes2 , attributes1 );
189169
190170 // Test hashCode
191171 assertThat (attributes1 .hashCode (), equalTo (attributes2 .hashCode ()));
@@ -195,19 +175,17 @@ public void testEqualsAndHashCode() {
195175 attributeMap3 .put ("key1" , Arrays .asList ("different" , "value2" ));
196176 attributeMap3 .put ("key2" , Collections .singletonList ("value3" ));
197177
198- SamlInitiateSingleSignOnAttributes attributes3 = new SamlInitiateSingleSignOnAttributes ();
199- attributes3 .setAttributes (attributeMap3 );
178+ SamlInitiateSingleSignOnAttributes attributes3 = new SamlInitiateSingleSignOnAttributes (attributeMap3 );
200179
201- assertFalse (attributes1 . equals ( attributes3 ) );
180+ assertNotEquals (attributes1 , attributes3 );
202181
203182 // Test with missing key
204183 Map <String , List <String >> attributeMap4 = new HashMap <>();
205184 attributeMap4 .put ("key1" , Arrays .asList ("value1" , "value2" ));
206185
207- SamlInitiateSingleSignOnAttributes attributes4 = new SamlInitiateSingleSignOnAttributes ();
208- attributes4 .setAttributes (attributeMap4 );
186+ SamlInitiateSingleSignOnAttributes attributes4 = new SamlInitiateSingleSignOnAttributes (attributeMap4 );
209187
210- assertFalse (attributes1 . equals ( attributes4 ) );
188+ assertNotEquals (attributes1 , attributes4 );
211189 }
212190
213191 private SamlInitiateSingleSignOnAttributes parseFromJson (String json ) throws IOException {
0 commit comments