/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2013 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
 */

package org.openlmis.order.dto;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openlmis.db.categories.UnitTests;
import org.openlmis.order.domain.Order;
import org.openlmis.rnr.domain.Rnr;

import java.text.SimpleDateFormat;

import static com.natpryce.makeiteasy.MakeItEasy.a;
import static com.natpryce.makeiteasy.MakeItEasy.make;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.openlmis.order.domain.OrderStatus.READY_TO_PACK;
import static org.openlmis.rnr.builder.RequisitionBuilder.defaultRequisition;

@Category(UnitTests.class)
public class OrderStatusFeedDTOTest {
  @Test
  public void shouldPopulateFeedFromRequisition() throws Exception {
    Rnr rnr = make(a(defaultRequisition));
    Order order = new Order(rnr);
    order.setStatus(READY_TO_PACK);
    OrderStatusFeedDTO feed = new OrderStatusFeedDTO(order);

    assertThat(feed.getRequisitionId(), is(rnr.getId()));
    assertThat(feed.getRequisitionStatus(), is(rnr.getStatus()));
    assertThat(feed.isEmergency(), is(rnr.isEmergency()));
    assertThat(feed.getStartDate(), is(rnr.getPeriod().getStartDate().getTime()));
    assertThat(feed.getEndDate(), is(rnr.getPeriod().getEndDate().getTime()));
    assertThat(feed.getOrderId(), is(order.getId()));
    assertThat(feed.getOrderStatus(), is(order.getStatus()));
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String stringStartDate = dateFormat.format(rnr.getPeriod().getStartDate());
    String stringEndDate = dateFormat.format(rnr.getPeriod().getEndDate());

    //assertThat(feed.getSerializedContents(), is("{\"requisitionId\":1,\"requisitionStatus\":\"INITIATED\",\"emergency\":false,\"startDate\":1325356200000,\"endDate\":1328034600000,\"stringStartDate\":\"" + stringStartDate + "\",\"stringEndDate\":\"" + stringEndDate + "\",\"orderId\":1,\"orderStatus\":\"READY_TO_PACK\"}"));
    assertThat(feed.getSerializedContents(), is("{\"requisitionId\":1,\"requisitionStatus\":\"INITIATED\",\"emergency\":false,\"startDate\":1325394000000,\"endDate\":1328072400000,\"orderId\":1,\"orderStatus\":\"READY_TO_PACK\"}"));
  }
}

@@ -2448,18 +2448,16 @@
 );%0A%0A    
-//
 assertTh
@@ -2593,11 +2593,11 @@
 3253
-562
+940
 0000
@@ -2619,11 +2619,11 @@
 3280
-346
+724
 0000
@@ -2773,240 +2773,8 @@
 ));%0A
-    assertThat(feed.getSerializedContents(), is(%22%7B%5C%22requisitionId%5C%22:1,%5C%22requisitionStatus%5C%22:%5C%22INITIATED%5C%22,%5C%22emergency%5C%22:false,%5C%22startDate%5C%22:1325394000000,%5C%22endDate%5C%22:1328072400000,%5C%22orderId%5C%22:1,%5C%22orderStatus%5C%22:%5C%22READY_TO_PACK%5C%22%7D%22));
 %0A  %7D

Fix system date issue in order status feed test