Search in sources :

Example 1 with Publication

use of cz.metacentrum.perun.cabinet.model.Publication in project perun by CESNET.

the class PublicationManagerIntegrationTest method updatePublicationTest.

@Test
public void updatePublicationTest() throws Exception {
    System.out.println("PublicationManagerIntegrationTest.updatePublicationTest");
    publicationOne.setMain("NEW MAIN");
    getCabinetManager().updatePublication(sess, publicationOne);
    Publication pub = getCabinetManager().getPublicationById(publicationOne.getId());
    assertEquals("Returned publication should be updated.", pub, publicationOne);
    assertEquals("Returned publication should be updated.", pub.getMain(), publicationOne.getMain());
}
Also used : Publication(cz.metacentrum.perun.cabinet.model.Publication) Test(org.junit.Test)

Example 2 with Publication

use of cz.metacentrum.perun.cabinet.model.Publication in project perun by CESNET.

the class PublicationManagerIntegrationTest method lockPublicationsTest.

@Test
public void lockPublicationsTest() throws Exception {
    System.out.println("PublicationManagerIntegrationTest.lockPublicationsTest");
    List<Publication> pubs = new ArrayList<Publication>();
    pubs.add(publicationOne);
    pubs.add(publicationTwo);
    boolean lock = publicationOne.getLocked();
    // switch lock to opposite
    getCabinetManager().lockPublications(sess, !lock, pubs);
    Publication result = getCabinetManager().getPublicationById(publicationOne.getId());
    assertTrue("PublicationOne was not locked/unlocked", result.getLocked() != lock);
    Publication result2 = getCabinetManager().getPublicationById(publicationTwo.getId());
    assertTrue("PublicationTwo was not locked/unlocked", result2.getLocked() != lock);
}
Also used : ArrayList(java.util.ArrayList) Publication(cz.metacentrum.perun.cabinet.model.Publication) Test(org.junit.Test)

Example 3 with Publication

use of cz.metacentrum.perun.cabinet.model.Publication in project perun by CESNET.

the class PublicationManagerIntegrationTest method updatePublicationWhenNotExistsTest.

@Test
public void updatePublicationWhenNotExistsTest() throws Exception {
    System.out.println("PublicationManagerIntegrationTest.updatePublicationWhenNotExistsTest");
    Publication pub = new Publication();
    try {
        getCabinetManager().updatePublication(sess, pub);
    } catch (CabinetException ex) {
        if (!ex.getType().equals(ErrorCodes.PUBLICATION_NOT_EXISTS)) {
            fail("Different exception code, was: " + ex.getType() + ", but expected: PUBLICATION_NOT_EXISTS.");
        // fail if different error
        }
    }
}
Also used : Publication(cz.metacentrum.perun.cabinet.model.Publication) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) Test(org.junit.Test)

Example 4 with Publication

use of cz.metacentrum.perun.cabinet.model.Publication in project perun by CESNET.

the class PublicationManagerIntegrationTest method getPublicationByIdOrExtIdTest.

@Test
public void getPublicationByIdOrExtIdTest() throws Exception {
    System.out.println("PublicationManagerIntegrationTest.getPublicationByIdOrExtIdTest");
    // search base on publicationOne ID
    Publication retrievedPub = getCabinetManager().getPublicationById(publicationOne.getId());
    assertTrue("Returned publications can't be null or empty.", (retrievedPub != null));
    assertTrue("Returned publication should be same as publicationOne.", Objects.equals(publicationOne, retrievedPub));
    // search base on publicationOne EXT_ID, PUB_SYS_ID
    retrievedPub = getCabinetManager().getPublicationByExternalId(publicationOne.getExternalId(), publicationOne.getPublicationSystemId());
    assertTrue("Returned publications can't be null or empty.", (retrievedPub != null));
    assertTrue("Returned publication should be same as publicationOne.", Objects.equals(publicationOne, retrievedPub));
}
Also used : Publication(cz.metacentrum.perun.cabinet.model.Publication) Test(org.junit.Test)

Example 5 with Publication

use of cz.metacentrum.perun.cabinet.model.Publication in project perun by CESNET.

the class PublicationManagerIntegrationTest method createInternalPublicationTest.

@Test
public void createInternalPublicationTest() throws Exception {
    System.out.println("PublicationManagerIntegrationTest.createInternalPublicationTest");
    Publication p = new Publication();
    p.setCategoryId(publicationOne.getCategoryId());
    // Pepa id 10, userId 1
    p.setCreatedBy(sess.getPerunPrincipal().getActor());
    p.setCreatedDate(new Date());
    // INTERNAL
    p.setExternalId(0);
    p.setIsbn("isbn 123-4556-899");
    p.setMain("KERBEROS main zaznam.");
    // INTERNAL
    p.setPublicationSystemId(0);
    p.setTitle("Kerberos");
    p.setYear(2010);
    p.setRank(0.0);
    p.setLocked(false);
    p.setDoi("DOI");
    p.setCreatedByUid(sess.getPerunPrincipal().getUserId());
    p = getCabinetManager().createPublication(sess, p);
    assertTrue(p.getId() > 0);
    // must be reset, since test update object after creation
    p.setExternalId(0);
    p.setPublicationSystemId(0);
    // double-check existence (based on isbn)
    try {
        getCabinetManager().createPublication(sess, p);
    } catch (CabinetException ex) {
        if (!ex.getType().equals(ErrorCodes.PUBLICATION_ALREADY_EXISTS)) {
            fail("Different exception was thrown when creating \"same\" internal publication: " + ex);
        }
    }
}
Also used : Publication(cz.metacentrum.perun.cabinet.model.Publication) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Publication (cz.metacentrum.perun.cabinet.model.Publication)20 CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 Author (cz.metacentrum.perun.cabinet.model.Author)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 Date (java.util.Date)5 Category (cz.metacentrum.perun.cabinet.model.Category)3 PublicationSystem (cz.metacentrum.perun.cabinet.model.PublicationSystem)3 IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3 SAXException (org.xml.sax.SAXException)3 SAXParseException (org.xml.sax.SAXParseException)3 Authorship (cz.metacentrum.perun.cabinet.model.Authorship)2 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)2 StringReader (java.io.StringReader)2 HashSet (java.util.HashSet)2