/*
 * Copyright 2013, Red Hat, Inc. and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.zanata.file;

import static javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE;
import static org.mockito.Mockito.doThrow;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.exception.ChunkUploadException;
import org.zanata.model.type.TranslationSourceType;

public class TranslationDocumentUploadTest extends DocumentUploadTest {

    private static final String ANY_LOCALE = "es";
    private static final String ANY_MERGETYPE = "auto";

    @Mock
    DocumentUploadUtil documentUploadUtil;

    private TranslationDocumentUpload transUpload;

    @Before
    public void beforeTest() {
        MockitoAnnotations.initMocks(this);
        seam.reset();
        seam.ignoreNonResolvable()
                .use("documentUploadUtil", documentUploadUtil).allowCycles();

        transUpload = seam.autowire(TranslationDocumentUpload.class);
    }

    @After
    public void clearResponse() {
        response = null;
    }

    @Test
    public void checksValidityAndFailsIfNotValid() {
        conf = defaultUpload().build();
        doThrow(new ChunkUploadException(NOT_ACCEPTABLE, "Test message")).when(
                documentUploadUtil).failIfUploadNotValid(conf.id,
                conf.uploadForm);
        response =
                transUpload.tryUploadTranslationFile(conf.id, ANY_LOCALE,
                        ANY_MERGETYPE, false, conf.uploadForm, TranslationSourceType.API_UPLOAD);
        assertResponseHasStatus(NOT_ACCEPTABLE);
        assertResponseHasErrorMessage("Test message");
        assertUploadTerminated();
    }

    // TODO damason: test failure when document does not exist
    // TODO damason: test failure if type is not po or adapter type
    // TODO damason: test failure if lacking translation upload permission
    // TODO damason: test basic translation upload successful

}

@@ -1001,115 +1001,8 @@
 e;%0A%0A
-import static javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE;%0Aimport static org.mockito.Mockito.doThrow;%0A%0A
 impo
@@ -1073,33 +1073,8 @@
 st;%0A
-import org.mockito.Mock;%0A
 impo
@@ -1112,58 +1112,8 @@
 ns;%0A
-import org.zanata.exception.ChunkUploadException;%0A
 impo
@@ -1161,16 +1161,51 @@
 eType;%0A%0A
+import javax.ws.rs.core.Response;%0A%0A
 public c
@@ -1381,62 +1381,8 @@
 %22;%0A%0A
-    @Mock%0A    DocumentUploadUtil documentUploadUtil;%0A%0A
     
@@ -1576,87 +1576,9 @@
 le()
-%0A                .use(%22documentUploadUtil%22, documentUploadUtil).allowCycles();%0A
+;
 %0A   
@@ -1758,26 +1758,9 @@
 oid 
-checksValidityAndF
+f
 ails
@@ -1764,21 +1764,24 @@
 ilsIfNot
-Valid
+LoggedIn
 () %7B%0A   
@@ -1821,188 +1821,8 @@
 ();%0A
-        doThrow(new ChunkUploadException(NOT_ACCEPTABLE, %22Test message%22)).when(%0A                documentUploadUtil).failIfUploadNotValid(conf.id,%0A                conf.uploadForm);%0A
     
@@ -2044,77 +2044,36 @@
 tus(
-NOT_ACCEPTABLE);%0A        assertResponseHasErrorMessage(%22Test message%22
+Response.Status.UNAUTHORIZED
 );%0A 

Fix TranslationDocumentUploadTest for CDI