package com.google.sps.servlets;

import com.google.sps.workspace.Workspace;
import com.google.sps.workspace.WorkspaceArchive;
import com.google.sps.workspace.WorkspaceFactory;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class DownloadWorkspaceTest {
  @Mock WorkspaceFactory workspaceFactory;
  @Mock HttpServletRequest req;
  @Mock HttpServletResponse resp;
  @Mock Workspace workspace;
  @Mock WorkspaceArchive archive;
  @Mock ServletOutputStream out;

  @InjectMocks DownloadWorkspace servlet;

  @Test
  public void doGet() throws Exception {
    /*final String WORKSPACE_ID = "WORKSPACE_ID";
    when(req.getParameter(eq("workspaceID"))).thenReturn(WORKSPACE_ID);
    when(workspaceFactory.fromWorkspaceID(WORKSPACE_ID)).thenReturn(workspace);
    when(workspace.getArchive()).thenReturn(archive);
    when(resp.getOutputStream()).thenReturn(out);

    servlet.doGet(req, resp);

    verify(req, times(1)).getParameter(eq("workspaceID"));
    verify(resp, times(1)).setContentType("application/x-gzip");
    verify(archive, times(1)).archive(out);*/
  }
}

@@ -38,184 +38,375 @@
 ort 
-com.google.sps.workspace.Workspace;%0Aimport com.google.sps.workspace.WorkspaceArchive;%0Aimport com.google.sps.workspace.WorkspaceFactory;%0Aimport javax.servlet.ServletOutputStream
+static org.mockito.ArgumentMatchers.anyString;%0Aimport static org.mockito.ArgumentMatchers.eq;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport com.google.appengine.api.blobstore.BlobKey;%0Aimport com.google.appengine.api.blobstore.BlobstoreService
 ;%0Aim
@@ -739,203 +739,107 @@
 ock 
-WorkspaceFactory workspaceFactory;%0A  @Mock HttpServletRequest req;%0A  @Mock HttpServletResponse resp;%0A  @Mock Workspace workspace;%0A  @Mock WorkspaceArchive archive;%0A  @Mock ServletOutputStream out
+BlobstoreService blobstoreService;%0A  @Mock HttpServletResponse resp;%0A  @Mock HttpServletRequest req
 ;%0A%0A 
@@ -937,51 +937,85 @@
     
-/*final String WORKSPACE_ID = %22WORKSPACE_ID
+BlobKey blobKey = mock(BlobKey.class);%0A%0A    final String filename = %22FILENAME
 %22;%0A 
@@ -1043,27 +1043,24 @@
 ter(eq(%22
-workspaceID
+filename
 %22))).the
@@ -1071,187 +1071,72 @@
 urn(
-WORKSPACE_ID);%0A    when(workspaceFactory.fromWorkspaceID(WORKSPACE_ID)).thenReturn(workspace);%0A    when(workspace.getArchive()).thenReturn(archive);%0A    when(resp.getOutputStream(
+filename);%0A    when(blobstoreService.createGsBlobKey(anyString()
 )).t
@@ -1145,19 +1145,23 @@
 nReturn(
-out
+blobKey
 );%0A%0A    
@@ -1234,19 +1234,16 @@
 eq(%22
-workspaceID
+filename
 %22));
@@ -1285,16 +1285,19 @@
 entType(
+eq(
 %22applica
@@ -1309,16 +1309,17 @@
 x-gzip%22)
+)
 ;%0A    ve
@@ -1327,42 +1327,184 @@
 ify(
-archive, times(1)).archive(out);*/
+blobstoreService, times(1))%0A        .createGsBlobKey(eq(%22/gs/fulfillment-deco-step-2020.appspot.com/%22 + filename));%0A    verify(blobstoreService, times(1)).serve(blobKey, resp);
 %0A  %7D

Fix DownloadWorkspaceTest.