Working upload of photos (individual and zip)
[photos] / src / test / java / org / wamblee / photos / model / AuthorizedAlbumTest.java
1 /*
2  * Copyright 2005-2011 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.photos.model;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import javax.servlet.http.HttpSession;
22
23 import org.wamblee.cache.Cache;
24 import org.wamblee.cache.EhCache;
25 import org.wamblee.io.ClassPathResource;
26 import org.wamblee.photos.model.authorization.AuthorizedAlbum;
27 import org.wamblee.security.authorization.AuthorizationService;
28 import org.wamblee.security.authorization.Operation;
29 import static org.mockito.Mockito.*;
30
31 /**
32  * Created with IntelliJ IDEA.
33  * User: erik
34  * Date: 9/23/13
35  * Time: 9:08 PM
36  * To change this template use File | Settings | File Templates.
37  */
38 public class AuthorizedAlbumTest extends AlbumTest {
39
40     @Override
41     protected Album createAlbum(File aDir, String aPath, Cache<String, ArrayList<PhotoEntry>> aCache)
42             throws IOException {
43         Album fileSystemAlbum = super.createAlbum(aDir, aPath,
44                 aCache);    //To change body of overridden methods use File | Settings | File Templates.
45         AuthorizationService service = mock(AuthorizationService.class);
46         when(service.isAllowed(anyObject(), any(Operation.class))).thenReturn(true);
47         HttpSession session = mock(HttpSession.class);
48         when(session.getId()).thenReturn("myid");
49         Album authorized = new AuthorizedAlbum(fileSystemAlbum, service, createCache(), session);
50         return authorized;
51     }
52
53     @Override
54     protected Cache createCache() {
55         try {
56             return new EhCache(new ClassPathResource("META-INF/ehcache.xml"), "test");
57         }
58         catch (Exception e) {
59             throw new RuntimeException(e.getMessage(), e);
60         }
61     }
62 }