44
55import gov .osti .entity .DOECodeMetadata ;
66import gov .osti .entity .Developer ;
7+ import gov .osti .entity .SponsoringOrganization ;
78import java .util .ArrayList ;
89import java .util .Arrays ;
910import java .util .List ;
1718import org .junit .Test ;
1819
1920/**
20- *
21+ * Test various METADATA related functionality.
22+ *
2123 * @author ensornl
2224 */
2325public class MetadataTest {
@@ -42,10 +44,10 @@ public void tearDown() {
4244 }
4345
4446 /**
45- * Test that PUBLISHED VALIDATIONS work.
47+ * Test that SUBMIT VALIDATIONS work.
4648 */
4749 @ Test
48- public void testValidatePublished () {
50+ public void testValidateSubmit () {
4951 DOECodeMetadata m = new DOECodeMetadata ();
5052
5153 // empty metadata should have numerous errors
@@ -59,7 +61,8 @@ public void testValidatePublished() {
5961 "Description is required." ,
6062 "A License is required." ,
6163 "At least one developer is required." ,
62- "A valid Landing Page URL is required for non-open source submissions."
64+ "A valid Landing Page URL is required for non-open source submissions." ,
65+ "Software type is required."
6366 };
6467
6568 for ( String message : validations ) {
@@ -75,6 +78,7 @@ public void testValidatePublished() {
7578 assertFalse ("Still requiring title?" , reasons .contains ("Software title is required." ));
7679 assertFalse ("Still requiring accessibility" , reasons .contains ("Missing Source Accessibility." ));
7780 assertTrue ("Missing OS validation" , reasons .contains ("Repository URL is required for open source submissions." ));
81+ assertTrue ("Missing software type validation" , reasons .contains ("Software type is required." ));
7882
7983 // test developer issues
8084 Developer d = new Developer ();
@@ -127,18 +131,37 @@ public void testValidatePublished() {
127131 m .setDevelopers (developers );
128132 m .setProprietaryUrl ("http://mylicense.com/terms.html" );
129133 m .setDescription ("This is a testing description." );
134+ m .setSoftwareType (DOECodeMetadata .Type .S );
130135
131136 reasons = Metadata .validateSubmit (m );
132137
133138 assertTrue ("Should be no more errors: " + StringUtils .join (reasons , ", " ), reasons .isEmpty ());
134139
140+ // assert that the BUSINESS additional requirement is there
141+ m .setSoftwareType (DOECodeMetadata .Type .B );
142+
143+ reasons = Metadata .validateSubmit (m );
144+
145+ assertFalse ("Missing business validation" , reasons .isEmpty ());
146+ assertTrue ("Reason is wrong" , reasons .contains ("A sponsor is required for Business software." ));
147+
148+ // fix it
149+ SponsoringOrganization sponsor = new SponsoringOrganization ();
150+ sponsor .setPrimaryAward ("AWARD" );
151+ sponsor .setOrganizationName ("Testing Business Validation" );
152+
153+ m .setSponsoringOrganizations (Arrays .asList (sponsor ));
154+
155+ reasons = Metadata .validateSubmit (m );
156+
157+ assertTrue ("Still have errors:" + StringUtils .join (reasons , ", " ), reasons .isEmpty ());
135158 }
136159
137160 /**
138- * Test some SUBMIT validations.
161+ * Test some ANNOUNCE validations.
139162 */
140163 @ Test
141- public void testValidateSubmit () {
164+ public void testValidateAnnounce () {
142165 // test that published ones also apply here
143166 DOECodeMetadata m = new DOECodeMetadata ();
144167
@@ -153,9 +176,10 @@ public void testValidateSubmit() {
153176 "Description is required." ,
154177 "A License is required." ,
155178 "At least one developer is required." ,
156- "A valid Landing Page URL is required for non-open source submissions."
179+ "A valid Landing Page URL is required for non-open source submissions." ,
180+ "Software type is required."
157181 };
158- String [] submit_validations = {
182+ String [] announce_validations = {
159183 "Release date is required." ,
160184 "At least one sponsoring organization is required." ,
161185 "At least one research organization is required." ,
@@ -169,8 +193,8 @@ public void testValidateSubmit() {
169193 assertTrue ("Missing: " + message , reasons .contains (message ));
170194 }
171195
172- // also check submit only validations
173- for ( String message : submit_validations ) {
196+ // also check announce only validations
197+ for ( String message : announce_validations ) {
174198 assertTrue ("Missing: " + message , reasons .contains (message ));
175199 }
176200 }
0 commit comments