bugfixes more or less for FilePortationTest in DocRepo

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4017 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
tosmers 2016-04-18 20:48:12 +00:00
parent 8dd5e30c87
commit a5a11848a5
6 changed files with 78 additions and 66 deletions

View File

@ -18,20 +18,12 @@
*/
package org.libreccm.core;
import static org.libreccm.core.CoreConstants.*;
import org.hibernate.annotations.GenericGenerator;
import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.security.Permission;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -47,6 +39,14 @@ import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static org.libreccm.core.CoreConstants.CORE_XML_NS;
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
/**
* Root class of all entities in LibreCCM which need categorisation and
@ -91,7 +91,12 @@ public class CcmObject implements Identifiable, Serializable {
@XmlElement(name = "object-id", namespace = CORE_XML_NS)
private long objectId;
@Column(name = "UUID", nullable = false)
/**
*
*/
@Column(name = "UUID", unique = true)
//@GeneratedValue(generator="uuid", strategy = GenerationType.AUTO)
//@GenericGenerator(name = "uuid", strategy = "uuid2")
@NotNull
@XmlElement(name = "uuid")
private String uuid;

View File

@ -18,12 +18,13 @@
*/
package org.libreccm.docrepo;
import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.core.CcmObject;
import org.libreccm.core.Identifiable;
import org.libreccm.security.User;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
@ -31,9 +32,9 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* Abstract entity class of a resource. Instances will be persisted into the
* database through the inheriting subclasses.
@ -47,6 +48,7 @@ import java.util.Date;
@Entity
@Table(schema = "CCM_DOCREPO", name = "RESOURCES")
public abstract class AbstractResource extends CcmObject {
private static final Logger log = Logger.getLogger(AbstractResource.class);
private static final long serialVersionUID = -910317798106611214L;
@ -74,7 +76,7 @@ public abstract class AbstractResource extends CcmObject {
* Mime-type of the {@code AbstractResource}.
*/
@Column(name = "MIME_TYPE")
private MimeType mimeType;
private String mimeType;
/**
* Size of the {@code AbstractResource}.
@ -85,16 +87,16 @@ public abstract class AbstractResource extends CcmObject {
/**
* Creation date of the {@code AbstractResource}.
*/
@Column(name = "CREATION_DATE")
@NotBlank
@Column(name = "CREATION_DATE", nullable = false)
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
/**
* Date of the latest modification of the {@code AbstractResource}.
*/
@Column(name = "LAST_MODIFIED_DATE")
@NotBlank
@Column(name = "LAST_MODIFIED_DATE", nullable = false)
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date lastModifiedDate;
@ -172,11 +174,18 @@ public abstract class AbstractResource extends CcmObject {
}
public MimeType getMimeType() {
return mimeType;
MimeType mimeType = null;
try {
mimeType = new MimeType(this.mimeType);
} catch (MimeTypeParseException e) {
log.error("Error on parsing the db-string for mimeType to actual" +
"MimeType", e);
}
return mimeType != null ? mimeType : null;
}
public void setMimeType(MimeType mimeType) {
this.mimeType = mimeType;
this.mimeType = mimeType.toString();
}
public long getSize() {

View File

@ -19,6 +19,8 @@
package org.libreccm.docrepo;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@ -34,6 +36,7 @@ import javax.persistence.Table;
*/
@Entity(name = "DocRepoFile")
@Table(schema = "CCM_DOCREPO", name = "FILES")
@NamedQueries({
@NamedQuery(name = "DocRepo.findFileByName",
query = "SELECT r FROM DocRepoFile r WHERE " +
@ -78,27 +81,4 @@ public class File extends AbstractResource {
//< End GETTER & SETTER
/**
* Returns the attribute names of this object class as a list of strings.
*
* @return List of strings with the attribute names of this class
*/
public static String[] getAttributeNames() {
return new String[] {
"name",
"description",
"path",
"mimeType",
"size",
"blobObject_ID",
"creationDate",
"lastModifiedDate",
"creationIp",
"lastModifiedIp",
"creator_ID",
"modifier_ID",
"parent_ID",
"repo_ID"
};
}
}

View File

@ -18,6 +18,7 @@
*/
package org.libreccm.docrepo.portation;
import org.apache.log4j.Logger;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
@ -30,21 +31,24 @@ import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.libreccm.docrepo.File;
import org.libreccm.docrepo.FileMarshaller;
import org.libreccm.docrepo.FileRepository;
import org.libreccm.portation.Format;
import org.libreccm.portation.Marshals;
import org.libreccm.tests.categories.IntegrationTest;
import javax.inject.Inject;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Date;
import java.util.UUID;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
@ -63,6 +67,7 @@ import static org.junit.Assert.assertTrue;
@Transactional(TransactionMode.COMMIT)
@CreateSchema({"create_ccm_docrepo_schema.sql"})
public class FilePortationTest {
private static final Logger log = Logger.getLogger(FilePortationTest.class);
@Inject
private FileRepository fileRepository;
@ -89,13 +94,6 @@ public class FilePortationTest {
@Before
public void setUp() {
// file = new File();
// file.setName("testname");
// file.setDescription("this is a text description");
// file.setPath("test/path");
// file.setCreationDate(new Date());
// file.setLastModifiedDate(new Date());
// fileRepository.save(file);
}
@After
@ -172,11 +170,27 @@ public class FilePortationTest {
}
@Test
@InSequence(20)
@InSequence(11)
public void fileRepositoryIsInjected() {
assertThat(fileRepository, is(not(nullValue())));
}
@Test
@InSequence(20)
public void fileShouldBeCreated() {
file = new File();
file.setUuid(UUID.randomUUID().toString());
file.setName("testname");
file.setDescription("this is a text description");
file.setPath(filePath + "test2.txt");
file.setCreationDate(new Date());
file.setLastModifiedDate(new Date());
if (fileRepository != null && file != null) {
log.info("HELLOOOOOO!!");
fileRepository.save(file);
}
}
@Test
@InSequence(100)
public void xmlShouldBeCreated() {
@ -190,17 +204,19 @@ public class FilePortationTest {
@InSequence(200)
public void aFileShouldBeCreated() {
java.io.File file = new java.io.File(filePath + "test.txt");
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file);
System.out.print("\n\n\n\n\n\n\n\n\n\n Fehler \n\n\n\n\n\n\n\n\n\n");
fileWriter.write("bloß ein test! - tosmers");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
System.out.print("\n\n\n\n\n\n\n\n\n\n Fehler \n\n\n\n\n\n\n\n\n\n");
if (!file.exists()) {
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file);
log.info("\n\n\n\n\n\n\n\n\n\n Success \n\n\n\n\n\n\n\n\n\n");
fileWriter.write("bloß ein test! - tosmers");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
log.error("\n\n\n\n\n\n\n\n\n\n Fehler \n\n\n\n\n\n\n\n\n\n");
}
assertTrue(file.exists());
}
assertTrue(file.exists());
}
}

View File

@ -72,6 +72,7 @@ CREATE SCHEMA ccm_docrepo;
create table CCM_CORE.CCM_OBJECTS (
OBJECT_ID bigint not null,
DISPLAY_NAME varchar(255),
UUID varchar(255) not null,
primary key (OBJECT_ID)
);
@ -675,7 +676,7 @@ CREATE SCHEMA ccm_docrepo;
DESCRIPTION varchar(255),
LAST_MODIFIED_DATE timestamp,
LAST_MODIFIED_IP varchar(255),
MIME_TYPE binary(255),
MIME_TYPE varchar(255),
NAME varchar(512) not null,
PATH varchar(255),
SIZE bigint,

View File

@ -72,6 +72,7 @@ CREATE SCHEMA ccm_docrepo;
create table CCM_CORE.CCM_OBJECTS (
OBJECT_ID bigint not null,
DISPLAY_NAME varchar(255),
UUID varchar(255) not null,
primary key (OBJECT_ID)
);
@ -675,7 +676,7 @@ CREATE SCHEMA ccm_docrepo;
DESCRIPTION varchar(255),
LAST_MODIFIED_DATE timestamp,
LAST_MODIFIED_IP varchar(255),
MIME_TYPE binary(255),
MIME_TYPE varchar(255),
NAME varchar(512) not null,
PATH varchar(255),
SIZE bigint,