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 [17/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/repository/ContainerRegistryRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRegistryRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRegistryRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRegistryRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,550 @@
+
+/*
+ * 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.repository;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Date;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.Container;
+import org.mitre.portal.model.ContainerRegistry;
+import org.mitre.portal.model.Gadget;
+import org.mitre.portal.model.GadgetAudience;
+import org.mitre.portal.model.GadgetAuthorType;
+import org.mitre.portal.model.GadgetSupportLinkType;
+import org.mitre.portal.model.GadgetTag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class ContainerRegistryRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private ContainerRegistryRepository containerRegistryRepository;
+
+ // test data
+ private final Long VALID_CONTAINER_REGISTRY_ID = new Long(1);
+ private final Long INVALID_CONTAINER_REGISTRY_ID = new Long(-1);
+ private final Long VALID_CONTAINER_ID = new Long(1);
+ private final Long INVALID_CONTAINER_ID = new Long(-1);
+
+ private final Long VALID_GADGET_ID = new Long(7);
+ private final String VALID_GADGET_URL = "http://www.test.com";
+ private URL validGadgetURL = null;
+ private final String VALID_GADGET_AUTHOR = "acarlucci";
+ private final String INVALID_GADGET_AUTHOR = "ZZZZTTT";
+ private final String VALID_AUTHOR_EMAIL = "test@example.com";
+ private final String VALID_AUTHOR_USER_ID = "100";
+ private final String VALID_GADGET_DESC = "Asdf";
+ private final String VALID_GADGET_TITLE = "GADGET Title";
+ private final String VALID_GADGET_THUMBNAIL_URL = "http://www.test.com/image.jpg";
+ private final Long VALID_AUDIENCE_ID = 2L;
+ private URL validThumbnailURL = null;
+ private final Long INVALID_GADGET_ID = new Long(-1);
+ private final String INVALID_AUTHOR_USER_ID = "9999999999999";
+ private final Long INVALID_AUDIENCE_ID = -99L;
+ private final String EXISTING_GADGET_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/employee_info.xml";
+ private URL existingGadgetURL = null;
+ private final Long VALID_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+ private GadgetSupportLinkType validGadgetSupportLinkType;
+ private final Long VALID_GADGET_AUTHOR_TYPE_ID = 1L;
+ private GadgetAuthorType validGadgetAuthorType;
+ private GadgetAuthorType invalidGadgetAuthorType;
+ private final String VALID_VERSION = "0.9.9";
+ private final boolean VALID_FEATURED = true;
+ private final String VALID_SCREENSHOT_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/sample.png";
+ private URL validScreenshotURL = null;
+ private final String VALID_QUERY_STRING = "mitre";
+ private final String INVALID_QUERY_STRING = "*$@!%";
+
+
+ @Before
+ public void setup() throws MalformedURLException {
+ validGadgetURL = new URL(VALID_GADGET_URL);
+ validThumbnailURL = new URL(VALID_GADGET_THUMBNAIL_URL);
+ validScreenshotURL = new URL(VALID_SCREENSHOT_URL);
+ existingGadgetURL = new URL(EXISTING_GADGET_URL);
+ validGadgetSupportLinkType = new GadgetSupportLinkType(VALID_GADGET_SUPPORT_LINK_TYPE_ID);
+ validGadgetAuthorType = new GadgetAuthorType(VALID_GADGET_AUTHOR_TYPE_ID);
+ invalidGadgetAuthorType = new GadgetAuthorType(-999L);
+ }
+
+ @Test
+ public void get_validContainerRegistryId_validContainerRegistry() {
+ ContainerRegistry result = containerRegistryRepository.get(VALID_CONTAINER_REGISTRY_ID);
+ assertEquals(VALID_CONTAINER_REGISTRY_ID, result.getContainerRegistryId());
+ assertEquals(VALID_CONTAINER_ID, result.getContainer().getContainerId());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidContainerRegistryId_exception() {
+ ContainerRegistry result = containerRegistryRepository.get(INVALID_CONTAINER_REGISTRY_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullContainerRegistryId_exception() {
+ ContainerRegistry result = containerRegistryRepository.get(null);
+ }
+
+ @Test
+ public void find_validContainer_validContainerRegistryList() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.find(container);
+ assertNotNull(list);
+ assertTrue("list size > 0", list.size() > 0);
+ for (ContainerRegistry cr : list) {
+ assertEquals(VALID_CONTAINER_ID, cr.getContainer().getContainerId());
+ }
+ }
+
+ @Test
+ public void find_invalidContainer_emptyContainerRegistryList() {
+ Container container = new Container(INVALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.find(container);
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void find_nullContainer_emptyContainerRegistryList() {
+ List<ContainerRegistry> list = containerRegistryRepository.find(null);
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void registerNewGadget_validGadget_validContainer() {
+ Container container = new Container(VALID_CONTAINER_ID);
+
+ Gadget gadget = new Gadget();
+ gadget.setUrl(validGadgetURL);
+ gadget.setAuthor(VALID_GADGET_AUTHOR);
+ gadget.setAuthorUserId(VALID_AUTHOR_USER_ID);
+ gadget.setGadgetAuthorType(validGadgetAuthorType);
+ gadget.setDescription(VALID_GADGET_DESC);
+ gadget.setTitle(VALID_GADGET_TITLE);
+ gadget.setThumbnailUrl(validThumbnailURL);
+ gadget.setScreenshotUrl(validScreenshotURL);
+ gadget.setGadgetSupportLinkType(validGadgetSupportLinkType);
+ gadget.setVersion(VALID_VERSION);
+ gadget.setFeatured(VALID_FEATURED);
+ gadget.setCreatedBy(VALID_AUTHOR_USER_ID);
+ gadget.setModifiedBy(VALID_AUTHOR_USER_ID);
+ gadget.setCreatedDate(new Date());
+ gadget.setModifiedDate(new Date());
+
+ containerRegistryRepository.registerNewGadget(gadget, container);
+
+ List<ContainerRegistry> list = containerRegistryRepository.find(container);
+
+ for(ContainerRegistry cr : list) {
+ if (cr.getGadget().getUrl().toString().equals(VALID_GADGET_URL)) {
+ assertNotNull(cr.getContainerRegistryId());
+ assertTrue(cr.getContainerRegistryId() > 0);
+ return;
+ }
+ }
+
+ fail("gadget not found in registry");
+ }
+
+ // TODO - make this test better when better error handling is implemented in gadget parsing
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void registerNewGadget_invalidGadget_validContainer_exception() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ Gadget gadget = new Gadget();
+ containerRegistryRepository.registerNewGadget(gadget, container);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void registerNewGadget_nullGadget_validContainer_exception() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ Gadget gadget = null;
+ containerRegistryRepository.registerNewGadget(gadget, container);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void registerNewGadget_validGadget_invalidContainer_exception() {
+ Container container = new Container();
+ Gadget gadget = new Gadget();
+ gadget.setGadgetId(VALID_GADGET_ID);
+ gadget.setUrl(validGadgetURL);
+ gadget.setAuthor(VALID_GADGET_AUTHOR);
+ gadget.setDescription(VALID_GADGET_DESC);
+ gadget.setTitle(VALID_GADGET_TITLE);
+ gadget.setThumbnailUrl(validThumbnailURL);
+ containerRegistryRepository.registerNewGadget(gadget, container);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void registerNewGadget_validGadget_nullContainer_exception() {
+ Container container = null;
+ Gadget gadget = new Gadget();
+ gadget.setGadgetId(VALID_GADGET_ID);
+ gadget.setUrl(validGadgetURL);
+ gadget.setAuthor(VALID_GADGET_AUTHOR);
+ gadget.setDescription(VALID_GADGET_DESC);
+ gadget.setTitle(VALID_GADGET_TITLE);
+ gadget.setThumbnailUrl(validThumbnailURL);
+ containerRegistryRepository.registerNewGadget(gadget, container);
+ }
+
+ // TODO - why isn't this test throwing a unique constraint error?
+ @Test(expected = Exception.class)
+ @Ignore
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void registerNewGadget_duplicateGadgetUrl_validContainer_exception() {
+ Container container = new Container(VALID_CONTAINER_ID);
+
+ Gadget gadget = new Gadget();
+ gadget.setUrl(existingGadgetURL);
+ gadget.setAuthor(VALID_GADGET_AUTHOR);
+ gadget.setDescription(VALID_GADGET_DESC);
+ gadget.setTitle(VALID_GADGET_TITLE);
+ gadget.setThumbnailUrl(validThumbnailURL);
+
+ containerRegistryRepository.registerNewGadget(gadget, container);
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_validContainerRegistry() {
+ ContainerRegistry cr = containerRegistryRepository.get(VALID_CONTAINER_REGISTRY_ID);
+ containerRegistryRepository.delete(cr);
+
+ ContainerRegistry cr2 = containerRegistryRepository.get(VALID_CONTAINER_REGISTRY_ID);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_invalidContainerRegistry() {
+ ContainerRegistry cr = new ContainerRegistry(INVALID_CONTAINER_REGISTRY_ID);
+ containerRegistryRepository.delete(cr);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_nullContainerRegistry() {
+ containerRegistryRepository.delete(null);
+ }
+
+ @Test
+ public void find_validContainer_validGadget_validContainerRegistry() {
+ final Long EXISTING_GADGET_ID = 1L;
+
+ Container container = new Container(VALID_CONTAINER_ID);
+ Gadget gadget = new Gadget(EXISTING_GADGET_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, gadget);
+ assertNotNull(cr);
+ assertEquals(container, cr.getContainer());
+ assertEquals(gadget, cr.getGadget());
+ assertNotNull(cr.getContainerRegistryId());
+ assertTrue(cr.getContainerRegistryId() > 0);
+ }
+
+ @Test
+ public void find_nullContainer_invalidGadget_validContainerRegistry() {
+ final Long INVALID_EXISTING_GADGET_ID = -1L;
+
+ Container container = null;
+ Gadget gadget = new Gadget(INVALID_EXISTING_GADGET_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, gadget);
+ assertNull(cr);
+ }
+
+ @Test
+ public void find_invalidContainer_validGadget_validContainerRegistry() {
+ final Long EXISTING_GADGET_ID = 1L;
+
+ Container container = new Container(INVALID_CONTAINER_ID);
+ Gadget gadget = new Gadget(EXISTING_GADGET_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, gadget);
+ assertNull(cr);
+ }
+
+ @Test
+ public void find_validContainer_nullGadget_validContainerRegistry() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ Gadget gadget = null;
+ ContainerRegistry cr = containerRegistryRepository.find(container, gadget);
+ assertNull(cr);
+ }
+
+ @Test
+ public void find_validContainer_invalidGadget_validContainerRegistry() {
+ final Long INVALID_EXISTING_GADGET_ID = -1L;
+
+ Container container = new Container(VALID_CONTAINER_ID);
+ Gadget gadget = new Gadget(INVALID_EXISTING_GADGET_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, gadget);
+ assertNull(cr);
+ }
+
+ @Test
+ public void find_validContainer_validGadgetUrl_validContainerRegistry() {
+ final Long EXISTING_GADGET_ID = 1L;
+
+ Container container = new Container(VALID_CONTAINER_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, existingGadgetURL);
+ assertNotNull(cr);
+ assertEquals(container, cr.getContainer());
+ assertEquals(EXISTING_GADGET_URL, cr.getGadget().getUrl().toString());
+ assertNotNull(cr.getContainerRegistryId());
+ assertTrue(cr.getContainerRegistryId() > 0);
+ }
+
+ @Test
+ public void find_invalidContainer_validGadgetUrl_nullContainerRegistry() {
+ final Long EXISTING_GADGET_ID = 1L;
+
+ Container container = new Container(INVALID_CONTAINER_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, validGadgetURL);
+ assertNull(cr);
+ }
+
+ @Test
+ public void find_validContainer_unregisteredGadgetUrl_nullContainerRegistry() throws MalformedURLException {
+ final String unregisteredUrl = "http://www.example.com/newgadget.xml";
+ URL url = new URL(unregisteredUrl);
+
+ Container container = new Container(VALID_CONTAINER_ID);
+ ContainerRegistry cr = containerRegistryRepository.find(container, url);
+ assertNull(cr);
+ }
+
+ @Test
+ public void findByAuthor_validAuthor() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByAuthor(container, VALID_GADGET_AUTHOR);
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ for (ContainerRegistry cr : list) {
+ assertEquals(VALID_GADGET_AUTHOR, cr.getGadget().getAuthor());
+ }
+ }
+
+ @Test
+ public void findByAuthor_inValidAuthor() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByAuthor(container, INVALID_GADGET_AUTHOR);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void findByAuthorUserId_validAuthorUserId() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByAuthorUserId(container, VALID_AUTHOR_USER_ID);
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ for (ContainerRegistry cr : list) {
+ assertEquals(VALID_AUTHOR_USER_ID, cr.getGadget().getAuthorUserId());
+ }
+ }
+
+ @Test
+ public void findByAuthorUserId_inValidAuthorUserId() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByAuthorUserId(container, INVALID_AUTHOR_USER_ID);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void findByGadgetAuthorType_validGadgetAuthorType() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetAuthorType(container, validGadgetAuthorType);
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ for (ContainerRegistry cr : list) {
+ assertEquals(validGadgetAuthorType.getGadgetAuthorTypeId(), cr.getGadget().getGadgetAuthorType().getGadgetAuthorTypeId());
+ }
+ }
+
+ @Test
+ public void findByGadgetAuthorType_invalidGadgetAuthorType() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetAuthorType(container, invalidGadgetAuthorType);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void findByTagName_validTagName() {
+ final String TAG_NAME = "news";
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByTagName(container, TAG_NAME);
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ assertEquals(2, list.size());
+ for (ContainerRegistry cr : list) {
+ boolean foundTag = false;
+ List<GadgetTag> gtList = cr.getGadget().getGadgetTagList();
+ for (GadgetTag gt : gtList) {
+ if (TAG_NAME.equals(gt.getTagName())) {
+ foundTag = true;
+ break;
+ }
+ }
+ assertTrue(foundTag);
+ }
+ }
+
+ @Test
+ public void findByTagName_invalidTagName() {
+ final String TAG_NAME = "ASDFASDFASDFASDFADSFASDF";
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByTagName(container, TAG_NAME);
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void findByTagName_nullContainer() {
+ final String TAG_NAME = "ASDFASDFASDFASDFADSFASDF";
+ Container container = null;
+ List<ContainerRegistry> list = containerRegistryRepository.findByTagName(container, TAG_NAME);
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void findByTagName_nullTagName() {
+ final String TAG_NAME = null;
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByTagName(container, TAG_NAME);
+ assertNotNull(list);
+ assertFalse("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void findByAudience_validAudience() {
+ GadgetAudience audience = new GadgetAudience(VALID_AUDIENCE_ID);
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByAudience(container, audience);
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ assertEquals(2, list.size());
+ for (ContainerRegistry cr : list) {
+ boolean foundAudience = false;
+ List<GadgetAudience> gaList = cr.getGadget().getGadgetAudienceList();
+ for (GadgetAudience ga : gaList) {
+ if (VALID_AUDIENCE_ID.equals(ga.getGadgetAudienceId())) {
+ foundAudience = true;
+ break;
+ }
+ }
+ assertTrue(foundAudience);
+ }
+ }
+
+
+ @Test
+ public void findByTitleOrDesc_validQueryString() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetTitleOrDesc(container, "%"+VALID_QUERY_STRING+"%");
+
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ //assertEquals(2, list.size());
+ for (ContainerRegistry cr : list) {
+ boolean foundMatch = false;
+ String title = cr.getGadget().getTitle();
+ String desc = cr.getGadget().getDescription();
+
+ if (title.toLowerCase().indexOf(VALID_QUERY_STRING.toLowerCase()) > 0) {
+ foundMatch = true;
+ break;
+ }
+ if (desc.toLowerCase().indexOf(VALID_QUERY_STRING.toLowerCase()) > 0) {
+ foundMatch = true;
+ break;
+ }
+
+ assertTrue(foundMatch);
+ }
+ }
+
+ @Test
+ public void findByTitleOrDesc_invalidQueryString() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetTitleOrDesc(container, INVALID_QUERY_STRING);
+
+ assertNotNull(list);
+ assertTrue("list is not empty", list.isEmpty());
+
+ }
+
+ @Test
+ public void findByTitleOrDesc_nullQueryString() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetTitleOrDesc(container, null);
+
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+
+ }
+
+ @Test
+ public void findByTitleOrDesc_blankQueryString() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetTitleOrDesc(container, "");
+
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+
+ }
+
+ @Test
+ public void findByGadgetId_validContainer_validGadgetId() {
+ Container container = new Container(VALID_CONTAINER_ID);
+ List<ContainerRegistry> list = containerRegistryRepository.findByGadgetId(container, VALID_GADGET_ID);
+
+ assertNotNull(list);
+ assertFalse("list is empty", list.isEmpty());
+
+ }
+
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRegistryRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,154 @@
+/*
+ * 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.repository;
+
+import java.util.List;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.Container;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ *
+ * A system test that verifies the components of the ContainerRepository work together.
+ * Uses Spring to bootstrap the application for use in a test environment.
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class ContainerRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests
+{
+ @Autowired
+ private ContainerRepository containerRepository;
+
+ // test data
+ private final Long VALID_ID = new Long(1);
+ private final String VALID_NAME = "default";
+ private final Long INVALID_ID = new Long(-1);
+ private final String INVALID_NAME = "ZZZ";
+
+ @Test
+ public void findAll_validList()
+ {
+ List<Container> result = containerRepository.findAll();
+ assertNotNull(result);
+ assertTrue("container list > 0", result.size() > 0);
+ assertEquals(VALID_NAME, result.get(0).getName());
+ }
+
+ @Test
+ public void get_validId_validContainer()
+ {
+ Container container = containerRepository.get(VALID_ID);
+ assertNotNull(container);
+ assertEquals(VALID_ID, container.getContainerId());
+ assertEquals(VALID_NAME, container.getName());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidId_exception()
+ {
+ Container container = containerRepository.get(INVALID_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullId_exception()
+ {
+ Container container = containerRepository.get(null);
+ }
+
+ @Test
+ public void find_validName_validContainer()
+ {
+ Container container = containerRepository.find(VALID_NAME);
+ assertNotNull(container);
+ assertEquals(VALID_ID, container.getContainerId());
+ assertEquals(VALID_NAME, container.getName());
+ }
+
+ @Test
+ public void find_invalidName_nullContainer()
+ {
+ Container container = containerRepository.find(INVALID_NAME);
+ assertNull(container);
+ }
+
+ @Test
+ public void find_nullName_nullContainer()
+ {
+ Container container = containerRepository.find(null);
+ assertNull(container);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validContainerNonNullId()
+ {
+ final String UPDATE_CONTAINER_NAME = "UPDATED_TEST_CONTAINER";
+
+ Container container = containerRepository.get(VALID_ID);
+ assertNotNull(container);
+ assertNotNull(container.getContainerId());
+ container.setName(UPDATE_CONTAINER_NAME);
+ containerRepository.save(container);
+
+ Container returnedContainer = containerRepository.get(VALID_ID);
+ assertNotNull(returnedContainer);
+ assertEquals(UPDATE_CONTAINER_NAME, returnedContainer.getName());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validContainerNullId()
+ {
+ final String newContainerName = "NEW_TEST_CONTAINER";
+
+ Container container = new Container();
+ container.setName(newContainerName);
+ assertNull("new containerId is null", container.getContainerId());
+
+ containerRepository.save(container);
+ assertNotNull(container.getContainerId());
+ assertTrue("container id > 0", container.getContainerId() > 0);
+
+ Container returnedContainer = containerRepository.find(newContainerName);
+ assertNotNull(returnedContainer);
+ assertEquals(newContainerName, returnedContainer.getName());
+ assertNotNull(returnedContainer.getContainerId());
+ assertTrue("returned container id > 0", returnedContainer.getContainerId() > 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_nullContainer()
+ {
+ containerRepository.save(null);
+ }
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/ContainerRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAudienceRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAudienceRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAudienceRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAudienceRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,213 @@
+
+/*
+ * 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.repository;
+
+import java.util.List;
+import org.junit.Test;
+import org.mitre.portal.model.GadgetAudience;
+import static org.junit.Assert.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.orm.jpa.JpaSystemException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetAudienceRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetAudienceRepository gadgetAudienceRepository;
+
+ private static final Long VALID_GADGET_AUDIENCE_ID = 1L;
+ private static final String VALID_CODE = "ALL";
+ private static final String VALID_DESCRIPTION = "All MITRE";
+
+ private static final Long INVALID_GADGET_AUDIENCE_ID = -1L;
+
+ @Test
+ public void get_validId_validGadgetAudience()
+ {
+ GadgetAudience ga = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ assertNotNull(ga);
+ assertEquals(VALID_GADGET_AUDIENCE_ID, ga.getGadgetAudienceId());
+ assertEquals(VALID_CODE, ga.getCode());
+ assertEquals(VALID_DESCRIPTION, ga.getDescription());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidId_exception()
+ {
+ GadgetAudience ga = gadgetAudienceRepository.get(INVALID_GADGET_AUDIENCE_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullId_exception()
+ {
+ GadgetAudience ga = gadgetAudienceRepository.get(null);
+ }
+
+ @Test
+ public void findAll_validList()
+ {
+ List<GadgetAudience> list = gadgetAudienceRepository.findAll();
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ String prevDesc = "";
+ for (GadgetAudience gss : list) {
+ assertTrue(gss.getDescription().compareTo(prevDesc) >= 0);
+ prevDesc = gss.getDescription();
+ }
+ }
+
+ @Test
+ public void findAllAssignedToGadgets_validList()
+ {
+ List<GadgetAudience> list = gadgetAudienceRepository.findAllAssignedToGadgets();
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ String prevDesc = "";
+ for (GadgetAudience gss : list) {
+ assertFalse(gss.getGadgetList().isEmpty());
+ assertTrue(gss.getDescription().compareTo(prevDesc) >= 0);
+ prevDesc = gss.getDescription();
+ }
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadgetAudienceNonNullId()
+ {
+ final String UPDATED_CODE = "ZYX";
+ final String UPDATED_DESCRIPTION = "Description2";
+
+ GadgetAudience ga = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ assertNotNull(ga);
+ assertNotNull(ga.getGadgetAudienceId());
+ ga.setCode(UPDATED_CODE);
+ ga.setDescription(UPDATED_DESCRIPTION);
+ gadgetAudienceRepository.save(ga);
+
+ GadgetAudience returnedGa = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ assertNotNull(returnedGa);
+ assertEquals(UPDATED_CODE, returnedGa.getCode());
+ assertEquals(UPDATED_DESCRIPTION, returnedGa.getDescription());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadgetAudienceNullId()
+ {
+ final String NEW_CODE = "QQQ";
+ final String NEW_DESCRIPTION = "Description555";
+
+ GadgetAudience ga = new GadgetAudience();
+ ga.setCode(NEW_CODE);
+ ga.setDescription(NEW_DESCRIPTION);
+ assertNull(ga.getGadgetAudienceId());
+
+ gadgetAudienceRepository.save(ga);
+ assertNotNull(ga.getGadgetAudienceId());
+ assertTrue(ga.getGadgetAudienceId() > 0);
+
+ Long newId = ga.getGadgetAudienceId();
+
+ GadgetAudience returnedGa = gadgetAudienceRepository.get(newId);
+ assertNotNull(returnedGa);
+ assertNotNull(returnedGa.getGadgetAudienceId());
+ assertEquals(newId, returnedGa.getGadgetAudienceId());
+ assertEquals(NEW_CODE, returnedGa.getCode());
+ assertEquals(NEW_DESCRIPTION, returnedGa.getDescription());
+ }
+
+ @Test(expected = NullPointerException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_nullGadgetAudience()
+ {
+ gadgetAudienceRepository.save(null);
+ }
+
+ @Test(expected = JpaSystemException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_duplicateAudienceCode_exception() {
+ final String DUPLICATE_AUDIENCE_CODE = "BED";
+
+ GadgetAudience ga = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ ga.setCode(DUPLICATE_AUDIENCE_CODE);
+ gadgetAudienceRepository.save(ga);
+ }
+
+ @Test(expected = JpaSystemException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_duplicateAudienceDescription_exception() {
+ final String DUPLICATE_AUDIENCE_DESCRIPTION = "Bedford";
+
+ GadgetAudience ga = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ ga.setDescription(DUPLICATE_AUDIENCE_DESCRIPTION);
+ gadgetAudienceRepository.save(ga);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_validGadgetAudience() {
+ GadgetAudience ga = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ gadgetAudienceRepository.delete(ga);
+
+ boolean gotExpectedException = false;
+ try {
+ GadgetAudience ga2 = gadgetAudienceRepository.get(VALID_GADGET_AUDIENCE_ID);
+ }
+ catch (IncorrectResultSizeDataAccessException e) {
+ gotExpectedException = true;
+ }
+
+ if (!gotExpectedException)
+ fail("delete did not work - get method found id after delete!");
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_invalidGadgetAudience() {
+ GadgetAudience ga = new GadgetAudience(INVALID_GADGET_AUDIENCE_ID);
+ gadgetAudienceRepository.delete(ga);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_nullGadgetAudience() {
+ gadgetAudienceRepository.delete(null);
+ }
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAudienceRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAuthorTypeRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAuthorTypeRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAuthorTypeRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAuthorTypeRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,55 @@
+
+/*
+ * 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.repository;
+
+import java.util.List;
+import org.junit.Test;
+import org.mitre.portal.model.GadgetAuthorType;
+import static org.junit.Assert.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetAuthorTypeRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetAuthorTypeRepository gadgetAuthorTypeRepository;
+
+ @Test
+ public void findAll_validList()
+ {
+ List<GadgetAuthorType> list = gadgetAuthorTypeRepository.findAll();
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ String prevDesc = "";
+ for (GadgetAuthorType gss : list) {
+ assertTrue(gss.getDescription().compareTo(prevDesc) >= 0);
+ prevDesc = gss.getDescription();
+ }
+ }
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetAuthorTypeRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetCommentRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetCommentRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetCommentRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetCommentRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,233 @@
+/*
+ * 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.repository;
+
+import java.util.Date;
+import java.util.List;
+import org.junit.Test;
+import org.mitre.portal.model.GadgetComment;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.mitre.portal.model.Gadget;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.orm.jpa.JpaSystemException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetCommentRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetCommentRepository gadgetCommentRepository;
+
+ private static final Long VALID_GADGET_COMMENT_ID = 1L;
+ private static final Long VALID_ADMIN_CREATED_GADGET_COMMENT_ID = 4L;
+ private static final String VALID_COMMENT_TEXT = "I liked this gadget";
+ private static final String VALID_USER_ID = "100";
+ private static final Long VALID_GADGET_ID = 1L;
+ private static final Long VALID_RATING_ID = 5L;
+ private static final String VALID_GADGET_VERSION = "1.0";
+
+ private static final Long INVALID_GADGET_COMMENT_ID = -1L;
+ private static final Long INVALID_GADGET_ID = -1L;
+
+ private Gadget validGadget;
+ private Gadget invalidGadget;
+
+ @Before
+ public void setup() {
+ validGadget = new Gadget(VALID_GADGET_ID);
+ invalidGadget = new Gadget(INVALID_GADGET_ID);
+ }
+
+ @Test
+ public void get_validId_validGadgetComment()
+ {
+ GadgetComment gc = gadgetCommentRepository.get(VALID_GADGET_COMMENT_ID);
+ assertNotNull(gc);
+ assertEquals(VALID_GADGET_COMMENT_ID, gc.getGadgetCommentId());
+ assertEquals(VALID_COMMENT_TEXT, gc.getCommentText());
+ assertEquals(VALID_USER_ID, gc.getUserId());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidId_exception()
+ {
+ gadgetCommentRepository.get(INVALID_GADGET_COMMENT_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullId_exception()
+ {
+ gadgetCommentRepository.get(null);
+ }
+
+ @Test
+ public void findByGadget_validGadget_validList()
+ {
+
+ List<GadgetComment> list = gadgetCommentRepository.findByGadget(validGadget);
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ Date prevDate = new Date(1999999999999L);
+ // verify the comments are sorted in date descending order on create date
+ for (GadgetComment gc : list) {
+ assertEquals(validGadget, gc.getGadget());
+ assertTrue(gc.getCreatedDate().before(prevDate));
+ prevDate = gc.getCreatedDate();
+ }
+ }
+
+ @Test
+ public void findByGadget_invalidGadget_emptyList()
+ {
+ List<GadgetComment> list = gadgetCommentRepository.findByGadget(invalidGadget);
+ assertNotNull(list);
+ assertTrue(list.isEmpty());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadgetCommentNullId()
+ {
+ String commentText = "My new comment";
+
+ GadgetComment gc = new GadgetComment();
+ gc.setCommentText(commentText);
+ gc.setGadget(validGadget);
+ gc.setGadgetRating(VALID_RATING_ID);
+ gc.setGadgetVersion(VALID_GADGET_VERSION);
+ gc.setUserId(VALID_USER_ID);
+ gc.setLastModifiedUserId(VALID_USER_ID);
+ assertNull(gc.getGadgetCommentId());
+
+ gadgetCommentRepository.save(gc);
+ assertNotNull(gc.getGadgetCommentId());
+ assertTrue(gc.getGadgetCommentId() > 0);
+
+ Long newId = gc.getGadgetCommentId();
+
+ GadgetComment returnedGc = gadgetCommentRepository.get(newId);
+ assertNotNull(returnedGc);
+ assertNotNull(returnedGc.getGadgetCommentId());
+ assertEquals(newId, returnedGc.getGadgetCommentId());
+ assertEquals(commentText, returnedGc.getCommentText());
+ assertNotNull(returnedGc.getCreatedDate());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadgetCommentNonNullId()
+ {
+ String UPDATED_COMMENT = "I changed my mind";
+
+ GadgetComment gc = gadgetCommentRepository.get(VALID_GADGET_COMMENT_ID);
+ assertNotNull(gc);
+ assertNotNull(gc.getGadgetCommentId());
+ assertFalse(UPDATED_COMMENT.equals(gc.getCommentText()));
+ gc.setCommentText(UPDATED_COMMENT);
+ gadgetCommentRepository.save(gc);
+
+ GadgetComment returnedGc = gadgetCommentRepository.get(VALID_GADGET_COMMENT_ID);
+ assertNotNull(returnedGc);
+ assertEquals(UPDATED_COMMENT, returnedGc.getCommentText());
+ assertNotNull(returnedGc.getLastModifiedDate());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadgetCommentNonNullIdAsAdmin()
+ {
+ GadgetComment gc = gadgetCommentRepository.get(VALID_ADMIN_CREATED_GADGET_COMMENT_ID);
+ assertNotNull(gc);
+ assertNotNull(gc.getGadgetCommentId());
+ assertTrue(gc.isCreatedByAdmin());
+
+ Date beforeCreatedDate = gc.getCreatedDate();
+ gadgetCommentRepository.save(gc);
+
+ GadgetComment returnedGc = gadgetCommentRepository.get(VALID_GADGET_COMMENT_ID);
+ assertNotNull(returnedGc);
+ assertNotNull(returnedGc.getLastModifiedDate());
+ assertFalse(gc.getCreatedDate().equals(beforeCreatedDate));
+ }
+
+ @Test(expected = NullPointerException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_nullGadgetComment()
+ {
+ gadgetCommentRepository.save(null);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_validGadgetComment() {
+ GadgetComment gc = gadgetCommentRepository.get(VALID_GADGET_COMMENT_ID);
+ gadgetCommentRepository.delete(gc);
+
+ boolean gotExpectedException = false;
+ try {
+ GadgetComment gc2 = gadgetCommentRepository.get(VALID_GADGET_COMMENT_ID);
+ }
+ catch (IncorrectResultSizeDataAccessException e) {
+ gotExpectedException = true;
+ }
+
+ if (!gotExpectedException)
+ fail("delete did not work - get method found id after delete!");
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_invalidGadgetComment() {
+ GadgetComment gc = new GadgetComment(INVALID_GADGET_COMMENT_ID);
+ gc.setGadget(validGadget);
+ gadgetCommentRepository.delete(gc);
+ }
+
+ @Test(expected = NullPointerException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_invalidGadgetComment_nullGadget() {
+ GadgetComment gc = new GadgetComment(INVALID_GADGET_COMMENT_ID);
+ gadgetCommentRepository.delete(gc);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_nullGadgetComment() {
+ gadgetCommentRepository.delete(null);
+ }
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetCommentRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRatingRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRatingRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRatingRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRatingRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ */
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.mitre.portal.repository;
+
+import java.util.ArrayList;
+import java.util.List;
+import static org.junit.Assert.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+import org.junit.Test;
+import org.mitre.portal.model.Gadget;
+import org.mitre.portal.model.GadgetRating;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+
+/**
+ *
+ * @author Sean Cooper
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetRatingRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetRatingRepository repository;
+ @Autowired
+ private GadgetRepository gadgetRepository;
+
+ private final Long VALID_GADGET_ID = 1L;
+ private final Long INVALID_ID = -1L;
+ private final String VALID_USER_ID = "28063";
+ private final String INVALID_USER_ID = "secooper";
+ private final Long VALID_GADGET_LIKE = 5L;
+ private final Long VALID_GADGET_DISLIKE = 0L;
+ private final Long VALID_GADGET_DELETE = -1L;
+
+ private GadgetRating createValidRating(Gadget gadget) {
+ return createValidRating(gadget, VALID_GADGET_LIKE);
+ }
+
+ private GadgetRating createValidRating(Gadget gadget, Long userRating) {
+ GadgetRating rating = new GadgetRating();
+ rating.setGadget(gadget);
+ rating.setUserId(VALID_USER_ID);
+ rating.setRating(userRating);
+ repository.save(rating);
+ return rating;
+ }
+
+ private GadgetRating getGadgetRatingDefinedInTestDataSql() {
+ return repository.get(1L);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void byId () {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ GadgetRating expected = createValidRating(gadget);
+ GadgetRating result = repository.get(expected.getGadgetRatingId());
+ assertEquals(expected, result);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void byGadget() {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ GadgetRating expected = createValidRating(gadget);
+ List<GadgetRating> results = repository.find(gadget);
+ assertTrue(results.contains(expected));
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void byGadgetAndUser() {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ GadgetRating expected = createValidRating(gadget);
+ GadgetRating result = repository.find(gadget, expected.getUserId());
+ assertEquals(expected, result);
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void byInvalidId() {
+ repository.get(INVALID_ID);
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void byInvalidGadget() {
+ Gadget gadget = gadgetRepository.get(INVALID_ID);
+ repository.find(gadget);
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void byInvalidUser() {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ createValidRating(gadget);
+ repository.find(gadget, INVALID_USER_ID);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void findByValidUser() {
+ //Add the rating from our test-data.sql file and then create another one just for good measure.
+ List<GadgetRating> expected = new ArrayList<GadgetRating>();
+ expected.add(getGadgetRatingDefinedInTestDataSql());
+ expected.add(createValidRating(gadgetRepository.get(VALID_GADGET_ID)));
+ List<GadgetRating> result = repository.find(VALID_USER_ID);
+ assertEquals(expected, result);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void findByInvalidUser() {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ createValidRating(gadget);
+ List<GadgetRating> result = repository.find(INVALID_USER_ID);
+ assertEquals(new ArrayList<GadgetRating>(), result);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void ratingUpdate () {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ GadgetRating expected = createValidRating(gadget, VALID_GADGET_LIKE);
+ expected.setRating(VALID_GADGET_DISLIKE);
+ repository.save(expected);
+ GadgetRating result = repository.get(expected.getGadgetRatingId());
+ assertEquals(expected, result);
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void ratingRemoval() {
+ Gadget gadget = gadgetRepository.get(VALID_GADGET_ID);
+ GadgetRating initial = createValidRating(gadget);
+ Long initialId = initial.getGadgetRatingId();
+ initial.setRating(VALID_GADGET_DELETE);
+ repository.save(initial);
+ repository.get(initialId);
+ }
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRatingRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,224 @@
+
+/*
+ * 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.repository;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.mitre.portal.model.Gadget;
+import org.mitre.portal.model.GadgetAudience;
+import org.mitre.portal.model.GadgetAuthorType;
+import org.mitre.portal.model.GadgetSupportLinkType;
+import org.mitre.portal.model.GadgetTag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetRepository gadgetRepository;
+
+ // test data
+ private final Long VALID_GADGET_ID = new Long(1);
+ private final String VALID_GADGET_TITLE = "Hello World";
+ private final String VALID_GADGET_DESC = "This is a Hello World gadget that also displays some dynamic javascript time. If you move this gadget around it will update the time!";
+ private final String VALID_GADGET_AUTHOR = "acarlucci";
+ private final String INVALID_GADGET_AUTHOR = "r102Author";
+ private final String VALID_GADGET_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/hello_world.xml";
+ private final Long VALID_SUPPORT_LINK_TYPE_ID = 2L;
+ private final Long VALID_AUTHOR_TYPE_ID = 1L;
+ private final String VALID_AUTHOR_MITRE_ID = "100";
+ private URL validGadgetURL = null;
+ private final String VALID_GADGET_THUMBNAIL_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/sample_thumbnail.png";
+ private URL validThumbnailURL = null;
+ private final Long INVALID_GADGET_ID = new Long(-1);
+
+
+ private Gadget gadget;
+
+ @Before
+ public void setup() throws MalformedURLException {
+ validGadgetURL = new URL(VALID_GADGET_URL);
+ validThumbnailURL = new URL(VALID_GADGET_THUMBNAIL_URL);
+
+ gadget = new Gadget();
+ gadget.setGadgetId(VALID_GADGET_ID);
+ gadget.setUrl(validGadgetURL);
+ gadget.setAuthor(VALID_GADGET_AUTHOR);
+ gadget.setDescription(VALID_GADGET_DESC);
+ gadget.setTitle(VALID_GADGET_TITLE);
+ gadget.setThumbnailUrl(validThumbnailURL);
+ }
+
+ @Test
+ public void get_validGadgetId_validGadget() {
+ Gadget result = gadgetRepository.get(VALID_GADGET_ID);
+ assertNotNull(result);
+ assertEquals(VALID_GADGET_ID, result.getGadgetId());
+ assertEquals(VALID_GADGET_URL, result.getUrl().toString());
+ assertEquals(VALID_GADGET_AUTHOR, result.getAuthor());
+ assertEquals(VALID_GADGET_DESC, result.getDescription());
+ assertEquals(VALID_GADGET_TITLE, result.getTitle());
+ assertEquals(VALID_GADGET_THUMBNAIL_URL, result.getThumbnailUrl().toString());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidGadgetId_exception() {
+ Gadget result = gadgetRepository.get(INVALID_GADGET_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullGadgetId_exception() {
+ Gadget result = gadgetRepository.get(null);
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_validGadget() {
+ Gadget g = gadgetRepository.get(VALID_GADGET_ID);
+ gadgetRepository.delete(g);
+
+ Gadget g2 = gadgetRepository.get(VALID_GADGET_ID);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_invalidGadget() {
+ Gadget g = new Gadget(INVALID_GADGET_ID);
+ gadgetRepository.delete(g);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void delete_nullGadget() {
+ gadgetRepository.delete(null);
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadget() throws MalformedURLException {
+ final String author = "NEW AUTHOR";
+ final String title = "new title";
+ final String description = "new desc";
+ final String thumbnailUrl = "http://www.example.com/newimage.png";
+
+ List<GadgetAudience> gadgetAudiences = new ArrayList<GadgetAudience>();
+ gadgetAudiences.add(new GadgetAudience(2L));
+ gadgetAudiences.add(new GadgetAudience(4L));
+
+ Gadget g = gadgetRepository.get(VALID_GADGET_ID);
+ g.setAuthor(author);
+ g.setTitle(title);
+ g.setDescription(description);
+ g.setThumbnailUrl(new URL(thumbnailUrl));
+ g.setGadgetAudienceList(gadgetAudiences);
+ gadgetRepository.save(g);
+
+ Gadget g2 = gadgetRepository.get(VALID_GADGET_ID);
+ assertNotNull(g2);
+ assertEquals(author, g2.getAuthor());
+ assertEquals(title, g2.getTitle());
+ assertEquals(description, g2.getDescription());
+ assertEquals(thumbnailUrl, g2.getThumbnailUrl().toString());
+ assertNotNull(g2.getGadgetAudienceList());
+ assertFalse(g2.getGadgetAudienceList().isEmpty());
+ assertEquals(gadgetAudiences.size(), g2.getGadgetAudienceList().size());
+ }
+
+ @Test
+ @Transactional(readOnly=false)
+ @Rollback(true)
+ public void save_validGadget_new() throws MalformedURLException {
+ final String author = "NEW AUTHOR";
+ final String title = "new title";
+ final String description = "new desc";
+ final String thumbnailUrl = "http://www.example.com/newimage.png";
+
+ List<GadgetAudience> gadgetAudiences = new ArrayList<GadgetAudience>();
+ gadgetAudiences.add(new GadgetAudience(2L));
+ gadgetAudiences.add(new GadgetAudience(4L));
+
+ Gadget g = new Gadget();
+ assertNull(g.getGadgetId());
+ g.setAuthor(author);
+ g.setTitle(title);
+ g.setUrl(new URL("http://example.com/fakeurl.xml"));
+ g.setGadgetSupportLinkType(new GadgetSupportLinkType(VALID_SUPPORT_LINK_TYPE_ID));
+ g.setGadgetAuthorType(new GadgetAuthorType(VALID_AUTHOR_TYPE_ID));
+ g.setSupportLink("test@example.com");
+ g.setVersion("1");
+ g.setDescription(description);
+ g.setThumbnailUrl(new URL(thumbnailUrl));
+ g.setGadgetAudienceList(gadgetAudiences);
+ g.setCreatedDate(new Date());
+ g.setCreatedBy(VALID_AUTHOR_MITRE_ID);
+ g.setModifiedDate(new Date());
+ g.setModifiedBy(VALID_AUTHOR_MITRE_ID);
+
+ List<GadgetTag> gadgetTags = new ArrayList<GadgetTag>();
+ GadgetTag gt1 = new GadgetTag();
+ gt1.setGadget(g);
+ gt1.setTagName("testtag1");
+ gadgetTags.add(gt1);
+ GadgetTag gt2 = new GadgetTag();
+ gt2.setGadget(g);
+ gt2.setTagName("testtag2");
+ gadgetTags.add(gt2);
+ g.setGadgetTagList(gadgetTags);
+
+ gadgetRepository.save(g);
+ assertNotNull(g.getGadgetId());
+
+ Gadget g2 = gadgetRepository.get(g.getGadgetId());
+ assertNotNull(g2);
+ assertEquals(author, g2.getAuthor());
+ assertEquals(title, g2.getTitle());
+ assertEquals(description, g2.getDescription());
+ assertEquals(thumbnailUrl, g2.getThumbnailUrl().toString());
+ assertNotNull(g2.getGadgetAudienceList());
+ assertFalse(g2.getGadgetAudienceList().isEmpty());
+ assertEquals(gadgetAudiences.size(), g2.getGadgetAudienceList().size());
+ assertEquals(VALID_SUPPORT_LINK_TYPE_ID, g2.getGadgetSupportLinkType().getGadgetSupportLinkTypeId());
+ assertEquals(gadgetTags.size(), g2.getGadgetTagList().size());
+ }
+
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetSupportLinkTypeRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetSupportLinkTypeRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetSupportLinkTypeRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetSupportLinkTypeRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,55 @@
+
+/*
+ * 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.repository;
+
+import java.util.List;
+import org.junit.Test;
+import org.mitre.portal.model.GadgetSupportLinkType;
+import static org.junit.Assert.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetSupportLinkTypeRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetSupportLinkTypeRepository gadgetSupportLinkTypeRepository;
+
+ @Test
+ public void findAll_validList()
+ {
+ List<GadgetSupportLinkType> list = gadgetSupportLinkTypeRepository.findAll();
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ String prevDesc = "";
+ for (GadgetSupportLinkType gss : list) {
+ assertTrue(gss.getDescription().compareTo(prevDesc) >= 0);
+ prevDesc = gss.getDescription();
+ }
+ }
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetSupportLinkTypeRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetTagRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetTagRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetTagRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetTagRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.repository;
+
+import org.junit.Test;
+import org.mitre.portal.model.GadgetAudience;
+import org.mitre.portal.model.GadgetTag;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: MAHADEVAN
+ * Date: May 7, 2010
+ * Time: 1:59:12 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetTagRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests
+{
+ @Autowired
+ private GadgetTagRepository gadgetTagRepository;
+
+ @Test
+ public void findAll_validList()
+ {
+ List<String> list = gadgetTagRepository.findAll();
+ assertNotNull(list);
+ assertFalse("list is not empty", list.isEmpty());
+ String prevTagName = "";
+ for (String s : list) {
+ assertTrue(s.compareTo(prevTagName) >= 0);
+ prevTagName = s;
+ }
+ }
+}
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetTagRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetUserPrefRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetUserPrefRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetUserPrefRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetUserPrefRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,122 @@
+
+/*
+ * 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.repository;
+
+import org.mitre.portal.repository.GadgetUserPrefRepository;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.Gadget;
+import org.mitre.portal.model.GadgetUserPref;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class GadgetUserPrefRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private GadgetUserPrefRepository gadgetUserPrefRepository;
+
+ // test data
+ private final Long VALID_GADGET_USER_PREF_ID = new Long(1);
+ private final Long VALID_GADGET_ID = new Long(6);
+ private final String VALID_NAME = "first_name";
+ private final String VALID_DISPLAY_NAME = "First Name";
+ private final String VALID_DATATYPE = "string";
+ private final boolean VALID_REQUIRED = true;
+ private final String VALID_DEFAULT_VALUE = "default name";
+ private final Long INVALID_GADGET_USER_PREF_ID = new Long(-1);
+ private final Long INVALID_GADGET_ID = new Long(-1);
+
+ private Gadget gadget;
+ private GadgetUserPref gadgetUserPref;
+
+ @Before
+ public void setup() {
+ gadget = new Gadget(VALID_GADGET_ID);
+
+ gadgetUserPref = new GadgetUserPref();
+ gadgetUserPref.setGadgetUserPrefId(VALID_GADGET_USER_PREF_ID);
+ gadgetUserPref.setDataType(VALID_DATATYPE);
+ gadgetUserPref.setDefaultValue(VALID_DEFAULT_VALUE);
+ gadgetUserPref.setDisplayName(VALID_DISPLAY_NAME);
+ gadgetUserPref.setGadget(gadget);
+ gadgetUserPref.setName(VALID_NAME);
+ gadgetUserPref.setRequired(VALID_REQUIRED);
+ }
+
+ @Test
+ public void get_validGadgetUserPrefId_validGadgetUserPref() {
+ GadgetUserPref result = gadgetUserPrefRepository.get(VALID_GADGET_USER_PREF_ID);
+ assertNotNull(result);
+ assertEquals(VALID_GADGET_USER_PREF_ID, result.getGadgetUserPrefId());
+ assertEquals(VALID_DATATYPE, result.getDataType());
+ assertEquals(VALID_DEFAULT_VALUE, result.getDefaultValue());
+ assertEquals(VALID_DISPLAY_NAME, result.getDisplayName());
+ assertEquals(VALID_GADGET_ID, result.getGadget().getGadgetId());
+ assertEquals(VALID_NAME, result.getName());
+ assertEquals(VALID_REQUIRED, result.getRequired());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidGadgetUserPrefId_exception() {
+ GadgetUserPref result = gadgetUserPrefRepository.get(INVALID_GADGET_USER_PREF_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullGadgetId_exception() {
+ GadgetUserPref result = gadgetUserPrefRepository.get(null);
+ }
+
+ @Test
+ public void find_validGadget_validGadgetUserPrefList() {
+ List<GadgetUserPref> list = gadgetUserPrefRepository.find(gadget);
+ assertNotNull(list);
+ assertTrue("list size > 0", list.size() > 0);
+ for (GadgetUserPref gp : list) {
+ assertEquals(VALID_GADGET_ID, gp.getGadget().getGadgetId());
+ }
+ }
+
+ @Test
+ public void find_invalidGadget_emptyGadgetUserPrefList() {
+ List<GadgetUserPref> list = gadgetUserPrefRepository.find(new Gadget(INVALID_GADGET_ID));
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+ @Test
+ public void find_nullGadget_emptyGadgetUserPrefList() {
+ List<GadgetUserPref> list = gadgetUserPrefRepository.find(null);
+ assertNotNull(list);
+ assertTrue("list is empty", list.isEmpty());
+ }
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/GadgetUserPrefRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/PageLayoutRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/PageLayoutRepositoryTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/PageLayoutRepositoryTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/PageLayoutRepositoryTest.java Fri Apr 1 16:42:22 2011
@@ -0,0 +1,82 @@
+
+/*
+ * 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.repository;
+
+import org.mitre.portal.repository.PageLayoutRepository;
+import java.util.List;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.PageLayout;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/system-test-config.xml"})
+@Transactional(readOnly=true)
+public class PageLayoutRepositoryTest extends AbstractTransactionalJUnit4SpringContextTests {
+ @Autowired
+ private PageLayoutRepository pageLayoutRepository;
+
+ // test data
+ private final Long VALID_ID = 1L;
+ private final String VALID_LAYOUT_NAME = "columns_1";
+ private final String VALID_DISPLAY_NAME = "One Column";
+ private final long VALID_RENDER_SEQ = 2L;
+ private final long VALID_NUM_REGIONS = 1L;
+ private final Long INVALID_ID = -1L;
+
+ @Test
+ public void get_validId_validPageLayout() {
+ PageLayout result = pageLayoutRepository.get(VALID_ID);
+ assertNotNull(result);
+ assertEquals(VALID_ID, result.getPageLayoutId());
+ assertEquals(VALID_LAYOUT_NAME, result.getLayoutName());
+ assertEquals(VALID_DISPLAY_NAME, result.getDisplayName());
+ assertEquals(VALID_RENDER_SEQ, result.getRenderSeq());
+ assertEquals(VALID_NUM_REGIONS, result.getNumRegions());
+ }
+
+ @Test(expected = IncorrectResultSizeDataAccessException.class)
+ public void get_invalidId_exception() {
+ PageLayout result = pageLayoutRepository.get(INVALID_ID);
+ }
+
+ @Test(expected = InvalidDataAccessApiUsageException.class)
+ public void get_nullId_exception() {
+ PageLayout result = pageLayoutRepository.get(null);
+ }
+
+ @Test
+ public void findAll_validList()
+ {
+ List<PageLayout> result = pageLayoutRepository.findAll();
+ assertNotNull(result);
+ assertTrue("list > 0", result.size() > 0);
+ }
+
+}
\ No newline at end of file
Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/repository/PageLayoutRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *