Ejemplo n.º 1
0
  @Test
  @Rollback(value = false)
  @Transactional(value = TxType.NEVER)
  public void storeEntity() throws IOException, PreviewTooLongException {
    Assert.assertEquals(printerProjectDao.getRowCount(), 0);
    project1 =
        createPrinterProject(
            PROJECT_1_NAME,
            PROJECT_1_DESCRIPTION,
            PROJECT_1_TAGS,
            PROJECT_1_CATEGORIES,
            ImageTools.loadImageFromResource(PROJECT_1_PREVIEW_FILE),
            PROJECT_1_USER);
    printerProjectDao.makePersistent(project1);
    Assert.assertNotNull(project1.getId());
    Assert.assertEquals(printerProjectDao.getRowCount(), 1);

    // Retrieve from database
    PrinterProject projectRetrieved = printerProjectDao.get(project1.getId());
    // Check new object.
    Assert.assertTrue(comparePrinterProjects(project1, projectRetrieved));

    // Add new Project
    project2 =
        createPrinterProject(
            PROJECT_2_NAME,
            PROJECT_2_DESCRIPTION,
            PROJECT_2_TAGS,
            PROJECT_2_CATEGORIES,
            ImageTools.loadImageFromResource(PROJECT_2_PREVIEW_FILE),
            PROJECT_2_USER);
    printerProjectDao.makePersistent(project2);
    Assert.assertNotNull(project2.getId());
    Assert.assertEquals(printerProjectDao.getRowCount(), 2);
  }
Ejemplo n.º 2
0
 public static PrinterProject createPrinterProject(
     String name,
     String description,
     Set<String> tags,
     Set<String> categories,
     byte[] preview,
     String user)
     throws PreviewTooLongException {
   PrinterProject project = new PrinterProject();
   project.setName(name);
   project.setDescription(description);
   project.setTags(tags);
   project.setPreview(preview);
   project.setCategories(categories);
   project.setCreatedBy(user);
   return project;
 }
Ejemplo n.º 3
0
  private boolean comparePrinterProjects(PrinterProject project1, PrinterProject project2) {
    if ((project1.getName() != null && project2.getName() == null)
        || (project1.getName() == null && project2.getName() != null)) {
      return false;
    }
    if (project1.getName() != null && project2.getName() != null) {
      if (!project1.getName().equals(project2.getName())) {
        return false;
      }
    }

    if ((project1.getDescription() != null && project2.getDescription() == null)
        || (project1.getDescription() == null && project2.getDescription() != null)) {
      return false;
    }
    if (project1.getDescription() != null && project2.getDescription() != null) {
      if (!project1.getDescription().equals(project2.getDescription())) {
        return false;
      }
    }

    if (project1.getTags() != null && project2.getTags() != null) {
      if (!project1.getTags().equals(project2.getTags())) {
        return false;
      }
    } else if (project1.getTags() == null || project2.getTags() == null) {
      return false;
    }

    if (project1.getCategories() != null && project2.getCategories() != null) {
      if (!project1.getCategories().equals(project2.getCategories())) {
        return false;
      }
    } else if (project1.getCategories() == null || project2.getCategories() == null) {
      return false;
    }

    if (!Arrays.equals(project1.getPreview(), project2.getPreview())) {
      return false;
    }

    return true;
  }