You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2011/04/01 18:42:42 UTC
svn commit: r1087796 [22/37] - in /incubator/rave/donations/mitre-osec: ./
conf/ db/ db/data/ db/sequences/ db/tables/ lib/ lib/apache-commons/
lib/apache-taglibs/ lib/build/ lib/build/cobertura/ lib/eclipselink/
lib/freemarker/ lib/google-collections/...
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_notfound_response.json
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_notfound_response.json?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_notfound_response.json (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_notfound_response.json Fri Apr 1 16:42:22 2011
@@ -0,0 +1,8 @@
+{
+ "gadgets":[
+ {"errors":["Unable to retrieve spec for http://dummy.example.com/bad_gadget_url. HTTP error 404"],
+ "moduleId":0,
+ "url":"http://dummy.example.com/bad_gadget_url"
+ }
+ ]
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_notfound_response.json
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response.json
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response.json?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response.json (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response.json Fri Apr 1 16:42:22 2011
@@ -0,0 +1,114 @@
+{
+ "gadgets": [
+ {"userPrefs":{
+ "openlist":{
+ "default":"",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"list",
+ "displayName":"List Type No Defaults"
+ },
+ "color":{
+ "default":"yellow",
+ "orderedEnumValues":[
+ {
+ "value":"red",
+ "displayValue":"Red (first)"
+ },{
+ "value":"aqua",
+ "displayValue":"Aqua (second)"
+ },{
+ "value":"lime",
+ "displayValue":"Lime (third)"
+ },{
+ "value":"yellow",
+ "displayValue":"Yellow (fourth)"
+ },{
+ "value":"pink",
+ "displayValue":"Pink (fifth)"
+ },{
+ "value":"orange","displayValue":"Orange (sixth)"
+ },{
+ "value":"white","displayValue":"White (seventh)"
+ }
+ ],
+ "enumValues":{
+ "orange":"Orange (sixth)",
+ "red":"Red (first)",
+ "white":"White (seventh)",
+ "pink":"Pink (fifth)",
+ "lime":"Lime (third)",
+ "yellow":"Yellow (fourth)",
+ "aqua":"Aqua (second)"
+ },
+ "type":"enum",
+ "displayName":"Color (Enum)"
+ },
+ "movies":{
+ "default":"Terminator|Forrest Gump|Predator",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"list",
+ "displayName":"List Type With Defaults 2"
+ },
+ "age":{
+ "default":"0",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"string",
+ "displayName":"Age"
+ },
+ "bool_test":{
+ "default":"",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"bool",
+ "displayName":"Boolean Type"
+ },
+ "hidden_test":{
+ "default":"unchangeable value",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"hidden",
+ "displayName":"Hidden Value"
+ },
+ "drinks":{
+ "default":"coke|pepsi|fruit punch",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"list",
+ "displayName":"List Type With Defaults"
+ },
+ "full_name":{
+ "default":"",
+ "orderedEnumValues":[],
+ "enumValues":{},
+ "type":"string",
+ "displayName":"Full Name"
+ }
+ },
+ "moduleId":0,
+ "screenshot": "http://content.example.com/mymii_v2/gadgets/images/repository/screenshots/mylinks_screenshot.png",
+ "authorEmail":"",
+ "singleton":false,
+ "width":0,
+ "authorLink":"",
+ "links":{},
+ "iframeUrl":"//http://localhost:/gadgets/ifr?url=http%3A%2F%2Fcontent.example.com%2Fgadgets%2Fsupported%2Fmy_links%2Fmy_links.xml&container=mymii&view=%25view%25&lang=%25lang%25&country=%25country%25&debug=%25debug%25&nocache=%25nocache%25&v=d03e27569913b6aea6e8c90da8608653&st=%25st%25",
+ "url":"http://dummy.example.com/dummy_gadget.xml",
+ "scaling":false,
+ "author":"CI&T",
+ "title":"My Links",
+ "height":0,
+ "titleUrl":"",
+ "thumbnail":"http://content.example.com/mymii_v2/gadgets/images/repository/thumbnails/mylinks.png",
+ "scrolling":false,
+ "views":{"default":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0},
+ "editCustomPrefs":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0}},
+ "features":["views","dynamic-height","core","opensocial-0.8"],
+ "showStats":false,
+ "categories":["",""],
+ "showInDirectory":false,
+ "authorPhoto":""}
+ ]
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response.json
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response_no_prefs.json
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response_no_prefs.json?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response_no_prefs.json (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response_no_prefs.json Fri Apr 1 16:42:22 2011
@@ -0,0 +1,28 @@
+{
+ "gadgets": [
+ {"userPrefs":{},
+ "moduleId":0,
+ "screenshot": "http://content.example.com/mymii_v2/gadgets/images/repository/screenshots/mylinks_screenshot.png",
+ "authorEmail":"",
+ "singleton":false,
+ "width":0,
+ "authorLink":"",
+ "links":{},
+ "iframeUrl":"//http://localhost:/gadgets/ifr?url=http%3A%2F%2Fcontent.example.com%2Fgadgets%2Fsupported%2Fmy_links%2Fmy_links.xml&container=mymii&view=%25view%25&lang=%25lang%25&country=%25country%25&debug=%25debug%25&nocache=%25nocache%25&v=d03e27569913b6aea6e8c90da8608653&st=%25st%25",
+ "url":"http://dummy.example.com/dummy_gadget.xml",
+ "scaling":false,
+ "author":"CI&T",
+ "title":"My Links",
+ "height":0,
+ "titleUrl":"",
+ "thumbnail":"http://content.example.com/mymii_v2/gadgets/images/repository/thumbnails/mylinks.png",
+ "scrolling":false,
+ "views":{"default":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0},
+ "editCustomPrefs":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0}},
+ "features":["views","dynamic-height","core","opensocial-0.8"],
+ "showStats":false,
+ "categories":["",""],
+ "showInDirectory":false,
+ "authorPhoto":""}
+ ]
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_response_no_prefs.json
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/util/PostMethodFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/util/PostMethodFactoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/util/PostMethodFactoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/util/PostMethodFactoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service.util;
+
+import java.io.UnsupportedEncodingException;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class PostMethodFactoryTest {
+ private PostMethodFactory postMethodFactory;
+
+ private final static String VALID_URL = "http://www.example.com/testservlet/";
+ private final static String VALID_CONTENT_TYPE = "application/json";
+ private final static String VALID_CHARSET = "UTF-8";
+ private final static String VALID_CONTENT = "{param: 'value'}";
+ private final static String INVALID_CHARSET = "THIS IS BAD";
+
+ @Before
+ public void setup() {
+ postMethodFactory = new PostMethodFactory();
+ }
+
+ @Test
+ public void getInstance_validUrl_validContent_validContentType_validCharset() throws UnsupportedEncodingException, URIException {
+ PostMethod pm = postMethodFactory.getInstance(VALID_URL, VALID_CONTENT, VALID_CONTENT_TYPE, VALID_CHARSET);
+ assertNotNull(pm);
+ assertEquals(VALID_URL, pm.getURI().toString());
+ assertEquals(VALID_CHARSET, pm.getRequestCharSet());
+ }
+
+ @Test(expected=UnsupportedEncodingException.class)
+ public void getInstance_validUrl_validContent_validContentType_invalidCharset() throws UnsupportedEncodingException, URIException {
+ PostMethod pm = postMethodFactory.getInstance(VALID_URL, VALID_CONTENT, VALID_CONTENT_TYPE, INVALID_CHARSET);
+ }
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/util/PostMethodFactoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/system-test-config.xml
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/system-test-config.xml?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/system-test-config.xml (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/system-test-config.xml Fri Apr 1 16:42:22 2011
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in
+ ~ compliance with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <!-- Configuration to support system testing of portal container -->
+
+ <!-- Imports application configuration -->
+ <import resource="classpath:/WEB-INF/applicationContext.xml" />
+
+ <!-- Creates an in-memory database populated with test data -->
+ <bean id="dataSource" class="org.mitre.jdbc.datasource.H2DataSourceFactory">
+ <property name="databaseName" value="mymii" />
+ <property name="scriptLocations" >
+ <list>
+ <value>file:db/sequences/create_all_seq.sql</value>
+ <value>file:db/tables/create_all_tables.sql</value>
+ <value>classpath:org/mitre/portal/testdb/test-data.sql</value>
+ </list>
+ </property>
+ </bean>
+
+ <!-- since we are using H2 as our testing db we need to update the databaseplatform property-->
+ <bean id="entityManagerFactory"
+ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
+ p:persistenceUnitName="portalPersistenceUnit"
+ p:dataSource-ref="dataSource">
+ <property name="jpaVendorAdapter">
+ <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
+ p:databasePlatform="org.eclipse.persistence.platform.database.OraclePlatform"
+ p:showSql="true" />
+ </property>
+ <property name="jpaPropertyMap">
+ <map>
+ <entry key="eclipselink.weaving" value="false" />
+ <entry key="eclipselink.logging.logger" value="org.eclipse.persistence.logging.CommonsLoggingSessionLog" />
+ <entry key="eclipselink.logging.level" value="FINE" />
+ <entry key="eclipselink.logging.level.sql" value="FINEST" />
+ <entry key="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform" />
+ </map>
+ </property>
+ </bean>
+
+ <!-- create a timerFactory with no scheduled tasks -->
+ <bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
+ <!-- Make sure this Timer uses a daemon thread to keep it from holding the JVM from exiting -->
+ <property name="daemon" value="true" />
+ <property name="scheduledTimerTasks">
+ <list></list>
+ </property>
+ </bean>
+
+</beans>
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/system-test-config.xml
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testdb/test-data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testdb/test-data.sql?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testdb/test-data.sql (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testdb/test-data.sql Fri Apr 1 16:42:22 2011
@@ -0,0 +1,251 @@
+--Copyright 2011 The MITRE Corporation --
+
+--Licensed under the Apache License, Version 2.0 (the "License");
+--you may not use this file except in compliance with the License.
+--You may obtain a copy of the License at
+
+-- http://www.apache.org/licenses/LICENSE-2.0
+
+--Unless required by applicable law or agreed to in writing, software
+--distributed under the License is distributed on an "AS IS" BASIS,
+--WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+--See the License for the specific language governing permissions and
+--limitations under the License.
+
+-- start container data ---
+insert into container (container_id, name) values (NEXT VALUE FOR container_id_seq, 'default');
+
+--- start person data ---
+insert into person (id, username, last_name, first_name, primary_email) values ('100', 'acarlucci', 'Carlucci', 'Tony', 'acarlucci@example.com');
+
+--- users matching those provided in the shindig canonicaldb.json sample data file
+insert into person (id, username, last_name, first_name, primary_email) values ('canonical', 'canonical', 'Digg', 'Shin', 'dev@shindig.apache.org');
+insert into person (id, username, last_name, first_name, primary_email) values ('john.doe', 'john.doe', 'Doe', 'John', 'john.doe@example.com');
+insert into person (id, username, last_name, first_name, primary_email) values ('jane.doe', 'jane.doe', 'Doe', 'Jane', 'jane.doe@example.com');
+insert into person (id, username, last_name, first_name, primary_email) values ('george.doe', 'george.doe', 'Doe', 'George', 'george.doe@example.com');
+insert into person (id, username, last_name, first_name, primary_email) values ('mario.rossi', 'mario.rossi', 'Rossi', 'Mario', 'mario.rossi@example.com');
+insert into person (id, username, last_name, first_name, primary_email) values ('maija.m', 'maija.m', 'Meikäläinen', 'Maija', 'maija.m@example.com');
+
+--- start wizard data ---
+insert into wizard (wizard_id, name, display_name, user_target, url) values (NEXT VALUE FOR wizard_id_seq, 'new_user', 'New User Wizard', 'all', 'http://dummy.example.com/new_user.html');
+insert into wizard (wizard_id, name, display_name, user_target, url) values (NEXT VALUE FOR wizard_id_seq, 'wizard2', 'Wizard 2', 'all', 'http://dummy.example.com/wizard2.html');
+
+--- start user wizard completed data ---
+insert into user_wizard_completed (user_wizard_completed_id, wizard_id, user_id) values (NEXT VALUE FOR user_wizard_completed_id_seq, 1, '100');
+insert into user_wizard_completed (user_wizard_completed_id, wizard_id, user_id) values (NEXT VALUE FOR user_wizard_completed_id_seq, 1, '11111');
+insert into user_wizard_completed (user_wizard_completed_id, wizard_id, user_id) values (NEXT VALUE FOR user_wizard_completed_id_seq, 1, '98765');
+
+--- start gadget author type data ---
+insert into gadget_author_type(gadget_author_type_id, code, description)
+values (gadget_author_type_id_seq.nextval, 'CIT', 'CI&T');
+
+insert into gadget_author_type(gadget_author_type_id, code, description)
+values (gadget_author_type_id_seq.nextval, 'EXT', 'External');
+
+insert into gadget_author_type(gadget_author_type_id, code, description)
+values (gadget_author_type_id_seq.nextval, 'EMP', 'MITRE Employee');
+
+insert into gadget_author_type(gadget_author_type_id, code, description)
+values (gadget_author_type_id_seq.nextval, 'GRP', 'MITRE Center/Group');
+
+--- start gadget support link type data ---
+insert into gadget_support_link_type(gadget_support_link_type_id, code, description)
+values (gadget_spprt_link_type_id_seq.nextval, 'HD', 'Help Desk');
+
+insert into gadget_support_link_type(gadget_support_link_type_id, code, description)
+values (gadget_spprt_link_type_id_seq.nextval, 'EMAIL', 'Email');
+
+insert into gadget_support_link_type(gadget_support_link_type_id, code, description)
+values (gadget_spprt_link_type_id_seq.nextval, 'URL', 'Url');
+
+insert into gadget_support_link_type(gadget_support_link_type_id, code, description)
+values (gadget_spprt_link_type_id_seq.nextval, 'NONE', 'None');
+--- end gadget support link type data ---
+
+--- start gadget audience data ---
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'ALL', 'All MITRE');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'MGR', 'Managers');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'ADMIN', 'Admins');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'DEV', 'Developers');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'CIIS', 'CIIS');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'CORP', 'Corporate');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'CAASD', 'CAASD');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'C2C', 'C2C');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'CEM', 'CEM');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'HLSC', 'HLSC');
+insert into gadget_audience(gadget_audience_id, code, description) values (gadget_audience_id_seq.nextval, 'BED', 'Bedford');
+--- end gadget audience data ---
+
+insert into gadget (gadget_id, title, description, author, url, thumbnail_url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'Hello World', 'This is a Hello World gadget that also displays some dynamic javascript time. If you move this gadget around it will update the time!', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/hello_world.xml','http://content.example.com/a/acarlucci/transfer/gadgets/sample_thumbnail.png','N',1,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'Y','N','Y');
+
+insert into gadget (gadget_id, title, description, author, url, thumbnail_url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'My Actions', 'A list of Actions you need to take care of.', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/my_actions.xml','http://content.example.com/a/acarlucci/transfer/gadgets/sample_thumbnail.png','N',1,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','Y');
+
+insert into gadget (gadget_id, title, description, author, url, thumbnail_url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'Employee Info', 'Your employee attribute information.', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/employee_info.xml','http://content.example.com/a/acarlucci/transfer/gadgets/sample_thumbnail.png','N',2,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','Y');
+
+insert into gadget (gadget_id, title, description, author, url, thumbnail_url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'Phonebook Sites JSON', 'A sample on how to retrieve json data via ajax.', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/pb-sites-json.xml','http://content.example.com/a/acarlucci/transfer/gadgets/sample_thumbnail.png','N',2,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','Y');
+
+insert into gadget (gadget_id, title, description, author, url, thumbnail_url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'MITRE News', 'The MITRE News Center - a static content example.', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/mitre_news.xml','http://content.example.com/a/acarlucci/transfer/gadgets/sample_thumbnail.png','N',3,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','Y');
+
+insert into gadget (gadget_id, title, description, author, url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'Simple Gadget', 'This is about as basic a gadget as you can make.', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/simple_gadget.xml','N',4,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','N');
+
+insert into gadget (gadget_id, title, description, author, url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'UNREGISTERED Gadget', 'AN UNREGISTERED GADGET', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/simple_gadget2.xml','N',1,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','Y');
+
+insert into gadget (gadget_id, title, description, author, url, use_custom_edit_ui,gadget_support_link_type_id, author_user_id, screenshot_url, version, featured, created_by, modified_by, created_date, modified_date, gadget_author_type_id, scrolling, hidden, send_comment_emails)
+values (NEXT VALUE FOR gadget_id_seq, 'fixed region gadget', 'a fixed region gadget', 'acarlucci', 'http://content.example.com/a/acarlucci/transfer/gadgets/simple_gadget3.xml','N',1,'100','http://example.com/screenshot.jpg','1.0.3','Y','100','100','2010-03-11','2010-03-11',1,'N','N','N');
+
+-- gadget audience map
+insert into gadget_audience_map (gadget_id, gadget_audience_id)
+values (1, 1);
+
+insert into gadget_audience_map (gadget_id, gadget_audience_id)
+values (1, 2);
+
+insert into gadget_audience_map (gadget_id, gadget_audience_id)
+values (2, 2);
+
+-- gadget tag
+insert into gadget_tag (gadget_tag_id, gadget_id, tag_name)
+values (gadget_tag_id_seq.nextval, 1, 'news');
+
+insert into gadget_tag (gadget_tag_id, gadget_id, tag_name)
+values (gadget_tag_id_seq.nextval, 1, 'tools');
+
+insert into gadget_tag (gadget_tag_id, gadget_id, tag_name)
+values (gadget_tag_id_seq.nextval, 2, 'news');
+
+insert into gadget_tag (gadget_tag_id, gadget_id, tag_name)
+values (gadget_tag_id_seq.nextval, 3, 'military');
+
+insert into gadget_user_pref (gadget_user_pref_id, gadget_id, name, display_name, datatype, required, default_value)
+values (NEXT VALUE FOR gadget_user_pref_id_seq, 6, 'first_name', 'First Name', 'string', 'Y', 'default name');
+
+insert into gadget_user_pref (gadget_user_pref_id, gadget_id, name, display_name, datatype, required, default_value)
+values (NEXT VALUE FOR gadget_user_pref_id_seq, 6, 'sample_list', 'Sample List', 'list', 'N', 'thing1|thing2');
+
+insert into gadget_user_pref_list_type (gadget_user_pref_list_type_id, gadget_user_pref_id, list_value, sort_value)
+values (NEXT VALUE FOR guplt_id_seq, 2, 'my list value 1', 1);
+
+insert into gadget_user_pref_list_type (gadget_user_pref_list_type_id, gadget_user_pref_id, list_value, sort_value)
+values (NEXT VALUE FOR guplt_id_seq, 2, 'my list value 2', 2);
+
+insert into container_registry (container_registry_id, container_id, gadget_id)
+select NEXT VALUE FOR container_registry_id_seq, 1, gadget_id
+from gadget
+where gadget_id <= 7;
+
+insert into person_gadget (person_gadget_id, gadget_id, user_id)
+select NEXT VALUE FOR person_gadget_id_seq, gadget_id, '100'
+from gadget;
+
+insert into page_layout (page_layout_id, layout_name, display_name, render_seq, num_regions, user_selectable)
+values (NEXT VALUE FOR page_layout_id_seq, 'columns_1', 'One Column', 2, 1, 'Y');
+
+insert into page_layout (page_layout_id, layout_name, display_name, render_seq, num_regions, user_selectable)
+values (NEXT VALUE FOR page_layout_id_seq, 'columns_3', 'Three Columns', 1, 3, 'Y');
+
+insert into page (page_id, container_id, user_id, name, page_layout_id, render_seq, fixed_layout)
+values (NEXT VALUE FOR page_id_seq, 1, '100', 'Home', 2, 1, 'Y');
+
+insert into page (page_id, container_id, user_id, name, page_layout_id, render_seq, fixed_layout)
+values (NEXT VALUE FOR page_id_seq, 1, '100', 'acarlucci Custom Page', 2, 2, 'N');
+
+insert into region (region_id, page_id, name)
+values (NEXT VALUE FOR region_id_seq, 1, 'region_1');
+
+insert into region (region_id, page_id, name)
+values (NEXT VALUE FOR region_id_seq, 1, 'region_2');
+
+insert into region (region_id, page_id, name)
+values (NEXT VALUE FOR region_id_seq, 1, 'region_3');
+
+insert into region_gadget (region_gadget_id, region_id, person_gadget_id, render_seq, collapsed)
+values (NEXT VALUE FOR region_gadget_id_seq, 1, 1, 1, 'N');
+
+insert into region_gadget (region_gadget_id, region_id, person_gadget_id, render_seq, collapsed)
+values (NEXT VALUE FOR region_gadget_id_seq, 2, 2, 1, 'N');
+
+insert into region_gadget (region_gadget_id, region_id, person_gadget_id, render_seq, collapsed)
+values (NEXT VALUE FOR region_gadget_id_seq, 3, 3, 1, 'N');
+
+insert into region_gadget (region_gadget_id, region_id, person_gadget_id, render_seq, collapsed)
+values (NEXT VALUE FOR region_gadget_id_seq, 3, 4, 2, 'N');
+
+insert into region_gadget (region_gadget_id, region_id, person_gadget_id, render_seq, collapsed)
+values (NEXT VALUE FOR region_gadget_id_seq, 3, 5, 3, 'N');
+
+insert into region_gadget (region_gadget_id, region_id, person_gadget_id, render_seq, collapsed)
+values (NEXT VALUE FOR region_gadget_id_seq, 3, 6, 4, 'Y');
+
+insert into page_template_owner_type (name, code)
+values ('Organization', 'ORG');
+
+insert into page_template_owner_type (name, code)
+values ('Employee', 'EMP');
+
+insert into page_template (page_template_id, container_id, name, page_layout_id, default_template, fixed_layout, description, owner_type_code, owner_type_value, owner_type_url, owner_type_logo, render_seq, fixed_name)
+values (NEXT VALUE FOR page_template_id_seq, 1, 'Empty', 1, 'N','N', 'Blank empty page.','ORG', 'CI&T','http://static.example.com/communications_services/ciandt/services/index.shtml', 'http://static.example.com/mymii_v2/container/images/cit_logo.gif',1, 'N');
+
+insert into page_template (page_template_id, container_id, name, page_layout_id, default_template, fixed_layout, description, owner_type_code, owner_type_value, owner_type_url, owner_type_logo, render_seq, fixed_name)
+values (NEXT VALUE FOR page_template_id_seq, 1, 'Home', 2, 'Y','Y', 'The default MyMII home page.','ORG', 'CI&T','http://static.example.com/communications_services/ciandt/services/index.shtml', 'http://static.example.com/mymii_v2/container/images/cit_logo.gif',2, 'N');
+
+insert into page_template_region (page_template_region_id, page_template_id, region_name)
+values (NEXT VALUE FOR page_template_region_id_seq, 2, 'region_1');
+insert into page_template_region (page_template_region_id, page_template_id, region_name)
+values (NEXT VALUE FOR page_template_region_id_seq, 2, 'region_2');
+insert into page_template_region (page_template_region_id, page_template_id, region_name)
+values (NEXT VALUE FOR page_template_region_id_seq, 2, 'region_3');
+
+insert into page_template_gadget(page_template_gadget_id, page_template_region_id, gadget_id, render_seq)
+values (NEXT VALUE FOR page_template_gadget_id_seq, 1, 8, 1);
+insert into page_template_gadget(page_template_gadget_id, page_template_region_id, gadget_id, render_seq)
+values (NEXT VALUE FOR page_template_gadget_id_seq, 3, 3, 1);
+insert into page_template_gadget(page_template_gadget_id, page_template_region_id, gadget_id, render_seq)
+values (NEXT VALUE FOR page_template_gadget_id_seq, 3, 2, 2);
+insert into page_template_gadget(page_template_gadget_id, page_template_region_id, gadget_id, render_seq)
+values (NEXT VALUE FOR page_template_gadget_id_seq, 3, 1, 3);
+
+insert into page_template (page_template_id, container_id, name, page_layout_id, default_template, fixed_layout, description, owner_type_code, owner_type_value, owner_type_url, owner_type_logo, render_seq, fixed_name)
+values (NEXT VALUE FOR page_template_id_seq, 1, 'R102 Employee Page', 3, 'N','N', 'The R102 page','ORG', 'R102',null, null,3, 'N');
+
+ insert into security_role(name, description, enabled)
+ values ('UNOFFICIAL_GADGET_DEVELOPER', 'A user who can develop gadgets and upload them to the repository as unofficial gadgets.', 'Y');
+ insert into security_role(name, description, enabled)
+ values ('OFFICIAL_GADGET_DEVELOPER', 'A user who can develop gadgets and upload them to the repository as official gadgets.', 'Y');
+ insert into security_role(name, description, enabled)
+ values ('ORG_PAGE_TEMPLATE_DEVELOPER', 'A user who can create page templates under the Dept, Center, or Division types and publish them for others to use.', 'Y');
+ insert into security_role(name, description, enabled)
+ values ('APPLICATION_ADMIN', 'General application admin tasks like setting up user security.', 'Y');
+ insert into security_role(name, description, enabled)
+ values ('REPOSITORY_ADMIN', 'Can perform gadget repository admin tasks like removing gadgets completely from the application.', 'Y');
+
+
+insert into security_user_role(id, user_id, security_role_name)
+values (NEXT VALUE FOR security_user_role_id_seq, '100', 'OFFICIAL_GADGET_DEVELOPER');
+insert into security_user_role(id, user_id, security_role_name)
+values (NEXT VALUE FOR security_user_role_id_seq,'100', 'ORG_PAGE_TEMPLATE_DEVELOPER');
+insert into security_user_role(id, user_id, security_role_name)
+values (NEXT VALUE FOR security_user_role_id_seq,'100', 'APPLICATION_ADMIN');
+insert into security_user_role(id, user_id, security_role_name)
+values (NEXT VALUE FOR security_user_role_id_seq,'100', 'REPOSITORY_ADMIN');
+
+insert into gadget_rating (gadget_rating_id, gadget_id, rating, user_id)
+values (next value for gadget_rating_id_seq, 1, 5, '28063');
+
+insert into gadget_comment (gadget_comment_id, gadget_id, user_id, comment_text, created_date, gadget_version, gadget_rating, last_modified_user_id, last_modified_date, last_modified_by_admin, created_by_admin)
+values (next value for gadget_comment_id_seq, 1, '100', 'I liked this gadget', '2010-10-05', '1.0', 5, '100','2010-10-05','N','N');
+
+insert into gadget_comment (gadget_comment_id, gadget_id, user_id, comment_text, created_date, gadget_version, gadget_rating, last_modified_user_id, last_modified_date, last_modified_by_admin, created_by_admin)
+values (next value for gadget_comment_id_seq, 1, '27677', 'I hated this gadget - swears omitted', '2010-10-06', '1.0', 0, '100', '2010-10-07', 'Y','N');
+
+insert into gadget_comment (gadget_comment_id, gadget_id, user_id, comment_text, created_date, gadget_version, gadget_rating, last_modified_user_id, last_modified_date, last_modified_by_admin, created_by_admin)
+values (next value for gadget_comment_id_seq, 1, '12345', 'I do not care either way', '2010-10-07', '1.0', null, '12345', '2010-10-07', 'N','N');
+
+insert into gadget_comment (gadget_comment_id, gadget_id, user_id, comment_text, created_date, gadget_version, gadget_rating, last_modified_user_id, last_modified_date, last_modified_by_admin, created_by_admin)
+values (next value for gadget_comment_id_seq, 1, '100', 'A new version coming soon', '2010-10-10', '1.0', null, '100', '2010-10-10', 'Y','Y');
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testdb/test-data.sql
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testutil/SetupConsoleLogger.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testutil/SetupConsoleLogger.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testutil/SetupConsoleLogger.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testutil/SetupConsoleLogger.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.testutil;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class SetupConsoleLogger
+{
+ private final static String CONSOLE_LOG_PATTERN = "%d %p [%c] - %m%n";
+
+ public static void setup(Logger rootLog)
+ {
+ rootLog.removeAllAppenders();
+ ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout(CONSOLE_LOG_PATTERN));
+ rootLog.addAppender(consoleAppender);
+ }
+}
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/testutil/SetupConsoleLogger.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/AdminControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/AdminControllerTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/AdminControllerTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/AdminControllerTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,405 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.web.controller;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mitre.portal.model.*;
+import org.mitre.portal.service.GadgetService;
+import org.mitre.portal.service.exception.GadgetAudienceNotFoundException;
+import org.mitre.portal.service.exception.UnknownGadgetException;
+import org.mitre.portal.web.util.ModelKeys;
+import org.mitre.portal.web.util.ViewNames;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.ui.ExtendedModelMap;
+import org.springframework.ui.Model;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class AdminControllerTest {
+ private GadgetService gadgetService;
+ private AdminController adminController;
+
+ private MockHttpServletRequest request;
+ private Container container;
+ private Model model;
+
+ private final Long VALID_CONTAINER_ID = 1L;
+ private final Long VALID_GADGET_AUDIENCE_ID = 1L;
+ private final String VALID_GADGET_AUDIENCE_CODE = "code";
+ private final String VALID_GADGET_AUDIENCE_DESC = "description";
+ private final String REDIRECT_GADGET_AUDIENCE = "redirect:viewGadgetAudience";
+ private List<GadgetAudience> validGadgetAudienceList;
+ private List<SecurityRole> validAllSecurityRoles;
+ private List<SecurityUserRole> validSecurityUserRoles;
+
+ private final String REDIRECT_SECURITY_USER_ROLE = "redirect:viewSecurityUserRole";
+ private final Long INVALID_GADGET_AUDIENCE_ID = -9991L;
+
+ private final String VALID_USERID = "34106";
+ private final String INVALID_USERID = "0";
+
+
+ @Before
+ public void setup() {
+ container = createNiceMock(Container.class);
+ expect(container.getContainerId()).andReturn(VALID_CONTAINER_ID).anyTimes();
+
+ gadgetService = createNiceMock(GadgetService.class);
+ request = new MockHttpServletRequest();
+
+ adminController = new AdminController(container, gadgetService);
+ model = new ExtendedModelMap();
+
+ validGadgetAudienceList = new ArrayList<GadgetAudience>();
+ validGadgetAudienceList.add(new GadgetAudience());
+ validGadgetAudienceList.add(new GadgetAudience());
+ validGadgetAudienceList.add(new GadgetAudience());
+
+ validAllSecurityRoles = new ArrayList<SecurityRole>();
+ validAllSecurityRoles.add(new SecurityRole());
+
+ validSecurityUserRoles = new ArrayList<SecurityUserRole>();
+ validSecurityUserRoles.add(new SecurityUserRole());
+
+
+ }
+
+ @Test
+ public void home_validModel_validViewName() {
+ replay(container);
+ String viewName = adminController.home(model);
+ assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+ assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+ assertEquals(ViewNames.Admin.HOME, viewName);
+ }
+
+ @Test
+ public void viewGadgetAudience_validModel_validViewName() {
+ expect(gadgetService.getAllAudiences()).andReturn(validGadgetAudienceList);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.viewGadgetAudience(model);
+ assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+ assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+ assertTrue(model.asMap().containsKey(ModelKeys.GADGET_AUDIENCE_LIST));
+ List<GadgetAudience> gaList = (List<GadgetAudience>) model.asMap().get(ModelKeys.GADGET_AUDIENCE_LIST);
+ assertEquals(validGadgetAudienceList, gaList);
+ assertEquals(ViewNames.Admin.GADGET_AUDIENCE, viewName);
+ }
+
+ @Test
+ public void saveGadgetAudience_validExistingGadgetAudience_validModel_validViewName() throws GadgetAudienceNotFoundException {
+ final String newCode = "ZZZ";
+ final String newDesc = "QQQQQQ";
+
+ GadgetAudience ga = new GadgetAudience();
+ ga.setGadgetAudienceId(VALID_GADGET_AUDIENCE_ID);
+ ga.setCode(newCode);
+ ga.setDescription(newDesc);
+
+ gadgetService.save(ga);
+ expect(gadgetService.getAllAudiences()).andReturn(validGadgetAudienceList);
+ expectLastCall();
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.saveGadgetAudience(VALID_GADGET_AUDIENCE_ID, newCode, newDesc, model);
+ assertEquals(REDIRECT_GADGET_AUDIENCE, viewName);
+ }
+
+ @Test
+ public void saveGadgetAudience_validNewGadgetAudience_validModel_validViewName() throws GadgetAudienceNotFoundException {
+ final String newCode = "ZZZ";
+ final String newDesc = "QQQQQQ";
+ final Long newId = 0L;
+
+ GadgetAudience ga = new GadgetAudience();
+ ga.setGadgetAudienceId(newId);
+ ga.setCode(newCode);
+ ga.setDescription(newDesc);
+
+ gadgetService.save(ga);
+ expectLastCall();
+ expect(gadgetService.getAllAudiences()).andReturn(validGadgetAudienceList);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.saveGadgetAudience(newId, newCode, newDesc, model);
+ assertEquals(REDIRECT_GADGET_AUDIENCE, viewName);
+ }
+
+ @Test
+ public void deleteGadgetAudience_validGadgetAudienceId_validModel_validViewName() throws GadgetAudienceNotFoundException {
+
+ GadgetAudience ga = new GadgetAudience();
+ ga.setGadgetAudienceId(VALID_GADGET_AUDIENCE_ID);
+
+ gadgetService.delete(ga);
+ expectLastCall();
+ expect(gadgetService.getAllAudiences()).andReturn(validGadgetAudienceList);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.deleteGadgetAudience(VALID_GADGET_AUDIENCE_ID, model);
+ assertEquals(REDIRECT_GADGET_AUDIENCE, viewName);
+ }
+
+
+
+ @Test
+ public void viewSecurityUserRole_validModel_validUserId()
+ {
+ expect(gadgetService.getAllSecurityRoles()).andReturn(validAllSecurityRoles);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.viewSecurityUserRole(VALID_USERID, model);
+
+ assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+ assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+ assertTrue(model.asMap().containsKey(ModelKeys.SECURITY_ROLES_LIST));
+ List<SecurityRole> secRoles = (List<SecurityRole>) model.asMap().get(ModelKeys.SECURITY_ROLES_LIST);
+ assertEquals(validAllSecurityRoles, secRoles);
+ assertEquals(ViewNames.Admin.SECURITY_USER_ROLE, viewName);
+ }
+
+
+ @Test
+ public void viewSecurityUserRole_validModel_NULL_UserId()
+ {
+ expect(gadgetService.getAllSecurityRoles()).andReturn(validAllSecurityRoles);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.viewSecurityUserRole(null, model);
+
+ assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+ assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+ assertTrue(model.asMap().containsKey(ModelKeys.SECURITY_ROLES_LIST));
+ List<SecurityRole> secRoles = (List<SecurityRole>) model.asMap().get(ModelKeys.SECURITY_ROLES_LIST);
+ assertEquals(validAllSecurityRoles, secRoles);
+ assertEquals(ViewNames.Admin.SECURITY_USER_ROLE, viewName);
+ }
+
+
+ @Test
+ public void getSecurityUserRoleByUser()
+ {
+ expect(gadgetService.getAllSecurityUserRoleByUserId(VALID_USERID)).andReturn(validSecurityUserRoles);
+ expect(gadgetService.getAllSecurityRoles()).andReturn(validAllSecurityRoles);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.getSecurityUserRoleByUser(VALID_USERID, model) ;
+
+ assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+ assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+ assertTrue(model.asMap().containsKey(ModelKeys.SECURITY_ROLES_LIST));
+
+ List<SecurityRole> secRoles = (List<SecurityRole>) model.asMap().get(ModelKeys.SECURITY_ROLES_LIST);
+ assertEquals(validAllSecurityRoles, secRoles);
+
+ List<SecurityUserRole> secUserRoles = (List<SecurityUserRole>) model.asMap().get(ModelKeys.SECURITY_USER_ROLE_LIST);
+ assertEquals(validSecurityUserRoles, secUserRoles);
+
+ assertEquals(ViewNames.Admin.SECURITY_USER_ROLE, viewName);
+ }
+
+ @Test
+ public void setSecurityUserRoleForUser_validUserId()
+ {
+ String[] userSecurityRoles = new String[1];
+ userSecurityRoles[0] = "APPLICATION_ADMIN" ;
+ List<SecurityUserRole> validSRoles = new ArrayList<SecurityUserRole>();
+ validSRoles.add(new SecurityUserRole(123L, VALID_USERID, "APPLICATION_ADMIN"));
+ SecurityUserRole sRole = new SecurityUserRole(123L, VALID_USERID, "APPLICATION_ADMIN") ;
+ gadgetService.delete(sRole);
+
+ expectLastCall();
+ expect(gadgetService.getAllSecurityRoles()).andReturn(validAllSecurityRoles);
+ expect(gadgetService.getAllSecurityUserRoleByUserId(VALID_USERID)).andReturn(validSRoles);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.setSecurityUserRoleForUser(VALID_USERID, userSecurityRoles, model) ;
+ //assertEquals("redirect:viewSecurityUserRole", viewName);
+ assertEquals(REDIRECT_SECURITY_USER_ROLE, viewName);
+
+
+ }
+
+ @Test
+ public void setSecurityUserRoleForUser_invalidUserId()
+ {
+ String[] userSecurityRoles = new String[0];
+
+ List<SecurityUserRole> validSRoles = new ArrayList<SecurityUserRole>();
+ validSRoles.add(new SecurityUserRole(123L, VALID_USERID, "APPLICATION_ADMIN"));
+ SecurityUserRole sRole = new SecurityUserRole(123L, VALID_USERID, "APPLICATION_ADMIN") ;
+ gadgetService.delete(sRole);
+
+ expectLastCall();
+ expect(gadgetService.getAllSecurityRoles()).andReturn(validAllSecurityRoles);
+ expect(gadgetService.getAllSecurityUserRoleByUserId(VALID_USERID)).andReturn(validSRoles);
+ replay(gadgetService);
+ replay(container);
+
+ String viewName = adminController.setSecurityUserRoleForUser(VALID_USERID, userSecurityRoles, model) ;
+ //assertEquals("redirect:viewSecurityUserRole", viewName);
+ assertEquals(REDIRECT_SECURITY_USER_ROLE, viewName);
+
+
+ }
+
+ @Test
+ public void refreshUserPrefsFromSpec_1() throws MalformedURLException, GadgetAudienceNotFoundException, UnknownGadgetException {
+ List<ContainerRegistry> regList = new ArrayList<ContainerRegistry>();
+
+ ContainerRegistry registry1 = new ContainerRegistry();
+ registry1.setGadget(new Gadget(1L, "mfranklin", "mfranklin", new URL("http://gadget.mitre.org/gadget1.xml")));
+
+ ContainerRegistry registry2 = new ContainerRegistry();
+ registry2.setGadget(new Gadget(2L, "mfranklin", "mfranklin", new URL("http://gadget.mitre.org/gadget2.xml")));
+
+ regList.add(registry1);
+ regList.add(registry2);
+
+ expect(container.getContainerRegistryList()).andReturn(regList).once();
+ replay(container);
+
+ Gadget newGadget1 = new Gadget(3L);
+ Gadget newGadget2 = new Gadget(4L);
+
+ expect(gadgetService.findGadgetFromUrl(registry1.getGadget().getUrl(), container)).andReturn(newGadget1);
+ expect(gadgetService.findGadgetFromUrl(registry2.getGadget().getUrl(), container)).andReturn(newGadget2);
+ gadgetService.updateUserPrefMetaData(registry1.getGadget(), newGadget1);
+ expectLastCall();
+ gadgetService.updateUserPrefMetaData(registry2.getGadget(), newGadget2);
+ expectLastCall();
+ gadgetService.save(registry1.getGadget());
+ expectLastCall();
+ gadgetService.save(registry2.getGadget());
+ expectLastCall();
+ replay(gadgetService);
+
+ Model model = new ExtendedModelMap();
+ adminController.refreshUserPrefsFromSpec(model);
+ verify(gadgetService);
+
+ List<String> result = (List<String>)model.asMap().get(ModelKeys.JSON_RESULT);
+ assertEquals("Successfully updated gadget 1 from http://gadget.mitre.org/gadget1.xml", result.get(0));
+ assertEquals("Successfully updated gadget 2 from http://gadget.mitre.org/gadget2.xml", result.get(1));
+ }
+
+
+ @Test
+ public void refreshUserPrefsFromSpec_2() throws MalformedURLException, GadgetAudienceNotFoundException, UnknownGadgetException {
+ List<ContainerRegistry> regList = new ArrayList<ContainerRegistry>();
+
+ ContainerRegistry registry1 = new ContainerRegistry();
+ registry1.setGadget(new Gadget(1L, "mfranklin", "mfranklin", new URL("http://gadget.mitre.org/gadget1.xml")));
+
+ ContainerRegistry registry2 = new ContainerRegistry();
+ registry2.setGadget(new Gadget(2L, "mfranklin", "mfranklin", new URL("http://gadget.mitre.org/gadget2.xml")));
+
+ regList.add(registry1);
+ regList.add(registry2);
+
+ expect(container.getContainerRegistryList()).andReturn(regList).once();
+ replay(container);
+
+ Gadget newGadget1 = new Gadget(3L);
+ Gadget newGadget2 = new Gadget(4L);
+
+ expect(gadgetService.findGadgetFromUrl(registry1.getGadget().getUrl(), container)).andReturn(null);
+ expect(gadgetService.findGadgetFromUrl(registry2.getGadget().getUrl(), container)).andReturn(newGadget2);
+ gadgetService.updateUserPrefMetaData(registry2.getGadget(), newGadget2);
+ expectLastCall();
+ gadgetService.save(registry2.getGadget());
+ expectLastCall();
+ replay(gadgetService);
+
+ Model model = new ExtendedModelMap();
+ adminController.refreshUserPrefsFromSpec(model);
+ verify(gadgetService);
+
+ List<String> result = (List<String>)model.asMap().get(ModelKeys.JSON_RESULT);
+ assertEquals("Failed to update gadget 1. Gadget Spec no longer exists at http://gadget.mitre.org/gadget1.xml", result.get(0));
+ assertEquals("Successfully updated gadget 2 from http://gadget.mitre.org/gadget2.xml", result.get(1));
+ }
+
+
+ @Test
+ public void refreshUserPrefsFromSpec_3() throws MalformedURLException, GadgetAudienceNotFoundException, UnknownGadgetException {
+ List<ContainerRegistry> regList = new ArrayList<ContainerRegistry>();
+
+ ContainerRegistry registry1 = new ContainerRegistry();
+ registry1.setGadget(new Gadget(1L, "mfranklin", "mfranklin", new URL("http://gadget.mitre.org/gadget1.xml")));
+
+ ContainerRegistry registry2 = new ContainerRegistry();
+ registry2.setGadget(new Gadget(2L, "mfranklin", "mfranklin", new URL("http://gadget.mitre.org/gadget2.xml")));
+
+ regList.add(registry1);
+ regList.add(registry2);
+
+ expect(container.getContainerRegistryList()).andReturn(regList).once();
+ replay(container);
+
+ Gadget newGadget1 = new Gadget(3L);
+ Gadget newGadget2 = new Gadget(4L);
+
+ expect(gadgetService.findGadgetFromUrl(registry1.getGadget().getUrl(), container)).andReturn(newGadget1);
+ expect(gadgetService.findGadgetFromUrl(registry2.getGadget().getUrl(), container)).andReturn(newGadget2);
+ gadgetService.updateUserPrefMetaData(registry1.getGadget(), newGadget1);
+ expectLastCall().andThrow(new RuntimeException("boo"));
+ gadgetService.updateUserPrefMetaData(registry2.getGadget(), newGadget2);
+ expectLastCall();
+ gadgetService.save(registry2.getGadget());
+ expectLastCall();
+ replay(gadgetService);
+
+ Model model = new ExtendedModelMap();
+ adminController.refreshUserPrefsFromSpec(model);
+ verify(gadgetService);
+
+ List<String> result = (List<String>)model.asMap().get(ModelKeys.JSON_RESULT);
+ assertEquals("Failed to update gadget 1 from http://gadget.mitre.org/gadget1.xml. Error: boo", result.get(0));
+ assertEquals("Successfully updated gadget 2 from http://gadget.mitre.org/gadget2.xml", result.get(1));
+ }
+
+
+
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/AdminControllerTest.java
------------------------------------------------------------------------------
svn:executable = *