Example #1
0
  @Test
  @SuppressWarnings("unchecked")
  public void edit() throws Exception {

    final DocumentClass documentClass = new DocumentClass("hello");
    final DocumentReference documentReference =
        newDocumentReference("hello.txt").withDocumentClass(documentClass).build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);
    SortedSet<Attribute> attributes = new TreeSet<>();
    attributes.add(new Attribute("a", false, AttributeDataType.CURRENCY));
    attributes.add(new Attribute("b", false, AttributeDataType.STRING));
    when(documentService.findAttributes(documentClass)).thenReturn(attributes);

    final ModelAndView modelAndView = controller.editDocument(1L);

    assertThat(modelAndView.getViewName(), is("edit.doc"));
    assertThat(modelAndView.getModel().size(), is(2));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    assertThat((DocumentReference) modelAndView.getModel().get("doc"), is(documentReference));
    assertThat(modelAndView.getModel().containsKey("attributes"), is(true));
    assertThat(((SortedSet<Attribute>) modelAndView.getModel().get("attributes")).size(), is(2));

    InOrder order = inOrder(documentService);
    order.verify(documentService).findDocumentReference(1L);
    order.verify(documentService).findAttributes(documentReference.getDocumentClass());
    order.verifyNoMoreInteractions();
  }
  @Test
  public void testEndpointConsumptionRelations() throws Exception {
    // Create endpoint consumption
    SoaNodeId endpointConsumptionId = new SoaNodeId(EndpointConsumption.DOCTYPE, "MyConsumption");
    DocumentModel endpointConsumptionModel =
        documentService.create(documentManager, endpointConsumptionId);
    EndpointConsumption endpointConsumption =
        endpointConsumptionModel.getAdapter(EndpointConsumption.class);
    Assert.assertNotNull("EndpointConsumption adapter must be available", endpointConsumption);
    documentManager.save();

    // Manipulate and test it
    Assert.assertNull(
        "EndpointConsumption must not initially consume endpoints",
        endpointConsumption.getConsumedEndpoint());
    SoaNodeId consumedEndpoint = new EndpointId("myenv", "myurl");
    endpointConsumption.setConsumedEndpoint(consumedEndpoint);
    Assert.assertEquals(
        "EndpointConsumption must be set as expected",
        consumedEndpoint,
        endpointConsumption.getConsumedEndpoint());
    DocumentModel foundEndpointModel =
        documentService.findSoaNode(documentManager, consumedEndpoint);
    Assert.assertNotNull("Consumed endpoint must be created", foundEndpointModel);
    endpointConsumption.setConsumedEndpoint(null);
    Assert.assertNull(
        "EndpointConsumption must be removed", endpointConsumption.getConsumedEndpoint());
  }
Example #3
0
  @Test
  public void editDocumentWithParams() throws DocumentNotFoundException {

    final DocumentReference documentReference =
        newDocumentReference("hello.txt")
            .withDocumentClass("test")
            .withIndex("name", "Silvio")
            .build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);
    when(documentService.updateIndices(documentReference)).thenReturn(documentReference);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("name", "Wangler");
    final ModelAndView modelAndView = controller.editDocument(1L, request);

    assertThat(modelAndView.getViewName(), is("import.successful"));
    assertThat(modelAndView.getModel().size(), is(1));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    final DocumentReference doc = (DocumentReference) modelAndView.getModel().get("doc");
    assertThat(doc, is(documentReference));
    assertThat(
        doc.getIndices().get(new TranslatableKey("name")).getValue().toString(), is("Wangler"));

    InOrder order = inOrder(documentService);

    order.verify(documentService).findDocumentReference(1L);
    order.verify(documentService).updateIndices(documentReference);
    order.verifyNoMoreInteractions();
  }
  @Test
  public void invoice_can_be_converted_to_ubl() throws IOException {
    byte[] xml = IOUtils.getResourceAsByteArray(RESOURCES_PATH + "/" + TEST_UBL_FILE_NAME);

    assertNotNull(xml);

    Invoice invoice = documentService.convertToInvoice(xml);

    assertNotNull(invoice);
    assertNotNull(invoice.getContent());

    byte[] convertedXml = documentService.convertToXml(invoice);

    assertNotNull(convertedXml);
  }
  @Test
  public void testServiceImplComplexProps() throws Exception {

    // Create ServiceImpl
    SoaNodeId serviceImplId = new SoaNodeId(ServiceImplementation.DOCTYPE, "MyServiceImpl");
    DocumentModel serviceImplModel = documentService.create(documentManager, serviceImplId);

    String opName = "Yo";
    String params = "Param1:java.lang.int, Param2:my.Class";
    String returnParams = "YoResponse:java.lang.String";
    String opDoc = "This does something";
    String inContentType = "text/xml";
    String outContentType =
        "application/json"; // http://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type

    // Use adapter to manipulate operations
    ServiceImplementation serviceImpl = serviceImplModel.getAdapter(ServiceImplementation.class);
    List<OperationInformation> operations = serviceImpl.getOperations();
    operations.add(
        new OperationInformation(
            opName, params, returnParams, opDoc, inContentType, outContentType));
    serviceImpl.setOperations(operations);
    List<String> tests = new ArrayList<String>();
    tests.add("org.easysoa.TestClass1");
    tests.add("org.easysoa.TestClass2");
    serviceImpl.setTests(tests);

    // Save
    documentManager.saveDocument(serviceImplModel);
    documentManager.save();

    // Fetch document again, check operations update
    serviceImplModel = documentService.findSoaNode(documentManager, serviceImplId);
    serviceImpl = serviceImplModel.getAdapter(ServiceImplementation.class);
    operations = serviceImpl.getOperations();
    Assert.assertEquals(1, operations.size());
    Assert.assertEquals(opName, operations.get(0).getName());
    Assert.assertEquals(params, operations.get(0).getParameters());
    Assert.assertEquals(returnParams, operations.get(0).getReturnParameters());
    Assert.assertEquals(opDoc, operations.get(0).getDocumentation());
    Assert.assertEquals(inContentType, operations.get(0).getInContentType());
    Assert.assertEquals(outContentType, operations.get(0).getOutContentType());
    Assert.assertEquals(opDoc, operations.get(0).getDocumentation());
    Assert.assertEquals(2, serviceImpl.getTests().size());
  }
Example #6
0
  @Test
  public void editDocumentWhenThrowsException() throws Exception {

    when(documentService.findDocumentReference(1L)).thenThrow(new DocumentNotFoundException(1L));

    final ModelAndView modelAndView = controller.editDocument(1L, new MockHttpServletRequest());

    assertThat(modelAndView.getViewName(), is("modification.doc.failed"));
    assertThat(modelAndView.getModel().isEmpty(), is(true));
  }
Example #7
0
  @Test
  public void editWhenThrowsException() throws Exception {

    when(documentService.findDocumentReference(1L)).thenThrow(new DocumentNotFoundException(1L));

    final ModelAndView modelAndView = controller.editDocument(1L);

    assertThat(modelAndView.getViewName(), is("edit.doc"));
    assertThat(modelAndView.getModel().isEmpty(), is(true));
  }
Example #8
0
  @Test
  public void getTheDocumentContentExpectNotFound()
      throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();
    long expectedDocumentId = 2L;
    when(documentService.findPhysicalDocument(expectedDocumentId))
        .thenThrow(new DocumentNotFoundException(expectedDocumentId));
    controller.getDocument(expectedDocumentId, response);
    assertThat(response.getStatus(), is(SC_NOT_FOUND));
  }
Example #9
0
  @Test
  public void getTheDocumentContentExpectNotFound3()
      throws DocumentNotFoundException, DocumentNotInStoreException, IOException {

    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getOutputStream()).thenThrow(new IOException());
    long expectedDocumentId = 2L;
    when(documentService.findPhysicalDocument(expectedDocumentId))
        .thenReturn(new PhysicalDocument());
    controller.getDocument(expectedDocumentId, response);

    verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
  }
  @Test
  public void testDocumentAdapters() throws ClientException {

    // Create a deliverable
    DocumentModel deliverableModel =
        documentService.create(
            documentManager,
            new SoaNodeId(Deliverable.DOCTYPE, "MyDeliverable"),
            DocumentModelHelper.getWorkspacesPath(documentManager, defaultSubprojectId));

    // Use its adapter
    Deliverable deliverable = deliverableModel.getAdapter(Deliverable.class);
    Assert.assertNotNull("Document model must be adapted as a deliverable", deliverable);
  }
 @RequestMapping(value = "/view.htm", method = RequestMethod.GET)
 public String view(ModelMap model, @RequestParam(value = "id", required = true) String id) {
   LOG.debug("viewing doc {} ", id);
   Assert.hasText(id);
   Document doc = docService.getDocument(id);
   model.addAttribute("document", doc);
   List<HistoricTask> hts = this.localTaskSrvc.getTaskHistory(id);
   model.addAttribute("historicTasks", hts);
   if (doc.isEditable(doc.getAuthor(), currentUserName())) {
     return "document/invoice/edit";
   }
   model.addAttribute("msg", "The invoice cannot be edited in its current state.");
   return "document/invoice/view";
 }
Example #12
0
  @Test
  public void getTheDocumentContentCausesAccessDenied()
      throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();

    PhysicalDocument physicalDocument =
        new PhysicalDocument(new DocumentClass("hhh"), "hello".getBytes(), null, "hello.txt");
    physicalDocument.setMimeType("aaa/bbb");
    when(documentService.findPhysicalDocument(1L)).thenThrow(new AccessDeniedException("YOLO"));

    controller.getDocument(1L, response);

    assertThat(response.getStatus(), is(SC_FORBIDDEN));
  }
Example #13
0
  @Test
  public void getTheDocumentContent()
      throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();

    PhysicalDocument physicalDocument =
        new PhysicalDocument(new DocumentClass("hhh"), "hello".getBytes(), null, "hello.txt");
    physicalDocument.setMimeType("aaa/bbb");
    when(documentService.findPhysicalDocument(1L)).thenReturn(physicalDocument);

    controller.getDocument(1L, response);

    assertThat(response.getStatus(), is(SC_OK));
    assertThat(response.getContentAsString(), is("hello"));
    assertThat(response.getContentType(), is("aaa/bbb"));
    assertThat(response.getHeader("Content-Disposition"), is("inline; filename=\"hello.txt\""));
  }
Example #14
0
  @Test
  public void editDocument() throws DocumentNotFoundException {

    final DocumentReference documentReference =
        newDocumentReference("hello.txt").withDocumentClass("test").build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);

    final ModelAndView modelAndView = controller.editDocument(1L, new MockHttpServletRequest());

    assertThat(modelAndView.getViewName(), is("import.successful"));
    assertThat(modelAndView.getModel().size(), is(1));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    assertThat((DocumentReference) modelAndView.getModel().get("doc"), is(documentReference));

    InOrder order = inOrder(documentService);

    order.verify(documentService).findDocumentReference(1L);
    order.verifyNoMoreInteractions();
  }
  @Test
  public void invoice_can_be_validated() throws IOException {
    byte[] xml = IOUtils.getResourceAsByteArray(RESOURCES_PATH + "/" + TEST_UBL_FILE_NAME);

    Invoice invoice = documentService.convertToInvoice(xml);

    assertNotNull(invoice);
    assertNotNull(invoice.getContent());

    assertNotNull(invoice.getContent().getID());
    assertEquals("HSD5", invoice.getContent().getID().getValue());

    assertNotNull(invoice.getContent().getAccountingCustomerParty());
    assertNotNull(invoice.getContent().getAccountingCustomerParty().getParty());
    assertNotNull(invoice.getContent().getAccountingCustomerParty().getParty().getPartyName());
    assertTrue(
        invoice.getContent().getAccountingCustomerParty().getParty().getPartyName().size() > 0);
    assertNotNull(
        invoice
            .getContent()
            .getAccountingCustomerParty()
            .getParty()
            .getPartyName()
            .get(0)
            .getName());
    assertEquals(
        "Lemberg",
        invoice
            .getContent()
            .getAccountingCustomerParty()
            .getParty()
            .getPartyName()
            .get(0)
            .getName()
            .getValue());

    assertNotNull(invoice.getContent().getAccountingCustomerParty().getParty().getPostalAddress());
    assertNotNull(
        invoice
            .getContent()
            .getAccountingCustomerParty()
            .getParty()
            .getPostalAddress()
            .getCountry());
    assertNotNull(
        invoice
            .getContent()
            .getAccountingCustomerParty()
            .getParty()
            .getPostalAddress()
            .getCountry()
            .getIdentificationCode());
    assertEquals(
        "UA",
        invoice
            .getContent()
            .getAccountingCustomerParty()
            .getParty()
            .getPostalAddress()
            .getCountry()
            .getIdentificationCode()
            .getValue());

    assertNotNull(invoice.getContent().getLegalMonetaryTotal());
    assertNotNull(invoice.getContent().getLegalMonetaryTotal().getPayableAmount());
    assertEquals(
        new BigDecimal("760.00"),
        invoice.getContent().getLegalMonetaryTotal().getPayableAmount().getValue());

    assertNotNull(invoice.getContent().getDocumentCurrencyCode());
    assertEquals("DKK", invoice.getContent().getDocumentCurrencyCode().getValue());
  }