• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account Log out
  • Favorite
  • Project
  • Recent History
Loading...
  • Log in
  • Sign up
kadrians / Testing_for_YONA star
  • Project homeH
  • CodeC
  • IssueI 1
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB 2
  • Files
  • Commit
  • Branches
Testing_for_YONAsourcetestmodelsAttachmentTest.java
Download as .zip file
File name
Commit message
Commit date
bin
Yona 1.16.0 Upload
02-04
lib
Yona 1.16.0 Upload
02-04
share/doc/api
Yona 1.16.0 Upload
02-04
source
Source Code Upload
02-04
README.md
Update README.md
02-04
File name
Commit message
Commit date
app
Source Code Upload
02-04
conf
Source Code Upload
02-04
docs
Source Code Upload
02-04
lib
Source Code Upload
02-04
project
Source Code Upload
02-04
public
Source Code Upload
02-04
support-script
Source Code Upload
02-04
test
Source Code Upload
02-04
.gitignore
Source Code Upload
02-04
.mailmap
Source Code Upload
02-04
.travis.yml
Source Code Upload
02-04
AUTHORS
Source Code Upload
02-04
LICENSE
Source Code Upload
02-04
NOTICE
Source Code Upload
02-04
README.md
Source Code Upload
02-04
build.sbt
Source Code Upload
02-04
dev.sh
Source Code Upload
02-04
dist.sh
Source Code Upload
02-04
is-alive-bot.sh
Source Code Upload
02-04
minify-js.sh
Source Code Upload
02-04
restart.sh
Source Code Upload
02-04
File name
Commit message
Commit date
actions/support
Source Code Upload
02-04
actors
Source Code Upload
02-04
controllers
Source Code Upload
02-04
mailbox
Source Code Upload
02-04
models
Source Code Upload
02-04
playRepository
Source Code Upload
02-04
support
Source Code Upload
02-04
utils
Source Code Upload
02-04
validation
Source Code Upload
02-04
File name
Commit message
Commit date
support
Source Code Upload
02-04
AttachmentTest.java
Source Code Upload
02-04
CodeCommentThreadTest.java
Source Code Upload
02-04
CommentTest.java
Source Code Upload
02-04
CommentThreadTest.java
Source Code Upload
02-04
CommitCommentTest.java
Source Code Upload
02-04
FileDiffTest.java
Source Code Upload
02-04
IssueTest.java
Source Code Upload
02-04
MilestoneTest.java
Source Code Upload
02-04
ModelTest.java
Source Code Upload
02-04
NotificationEventTest.java
Source Code Upload
02-04
NotificationMailTest.java
Source Code Upload
02-04
OrganizationTest.java
Source Code Upload
02-04
OrganizationUserTest.java
Source Code Upload
02-04
PasswordResetTest.java
Source Code Upload
02-04
PostingTest.java
Source Code Upload
02-04
ProjectTest.java
Source Code Upload
02-04
ProjectUserTest.java
Source Code Upload
02-04
PullRequestEventTest.java
Source Code Upload
02-04
PullRequestTest.java
Source Code Upload
02-04
RecentlyVisitedProjectsTest.java
Source Code Upload
02-04
ReviewCommentTest.java
Source Code Upload
02-04
RoleTest.java
Source Code Upload
02-04
SearchResultTests.java
Source Code Upload
02-04
SearchTests.java
Source Code Upload
02-04
TimelineItemTest.java
Source Code Upload
02-04
UserTest.java
Source Code Upload
02-04
WatchTest.java
Source Code Upload
02-04
Nell 02-04 97c4951 Source Code Upload UNIX
Raw Open in browser Change history
/** * Yobi, Project Hosting SW * * Copyright 2012 NAVER Corp. * http://yobi.io * * @Author Yi EungJun * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package models; import static org.fest.assertions.Assertions.assertThat; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.List; import org.junit.Before; import org.junit.Test; public class AttachmentTest extends ModelTest<Attachment> { @Before public void before() { Attachment.setUploadDirectory("resources/test/uploads"); } @Test public void testSaveInUserTemporaryArea() throws IOException, NoSuchAlgorithmException { // Given File file = createFileWithContents("foo.txt", "Hello".getBytes()); Long userId = 1L; // When Attachment attach = new Attachment(); attach.store(file, "bar.txt", User.find.byId(userId).asResource()); FileInputStream is = new FileInputStream(attach.getFile()); byte[] b = new byte[1024]; int length = is.read(b); is.close(); // Then assertThat(attach.name).isEqualTo("bar.txt"); assertThat(attach.mimeType).isEqualTo("text/plain; charset=UTF-8"); assertThat(new String(b, 0, length)).isEqualTo(new String("Hello")); } @Test public void testMoveOnlySelected() throws Exception { // Given File foo = createFileWithContents("foo.txt", "Hello".getBytes()); File bar = createFileWithContents("bar.html", "<p>Bye</p>".getBytes()); Issue issue = Issue.finder.byId(1L); User user = User.findByLoginId("doortts"); Attachment thisOne = new Attachment(); Attachment notThis = new Attachment(); thisOne.store(foo, "foo.txt", user.asResource()); notThis.store(bar, "bar.html", user.asResource()); String[] selectedFileIds = {thisOne.id + ""}; // When Attachment.moveOnlySelected(user.asResource(), issue.asResource(), selectedFileIds); // Then List<Attachment> attachedFiles = Attachment.findByContainer(issue.asResource()); List<Attachment> unattachedFiles = Attachment.findByContainer(user.asResource()); assertThat(attachedFiles.size()).isEqualTo(1); assertThat(unattachedFiles.size()).isEqualTo(1); } public void testAttachFiles() throws IOException, NoSuchAlgorithmException { // Given File foo = createFileWithContents("foo.txt", "Hello".getBytes()); File bar = createFileWithContents("bar.html", "<p>Bye</p>".getBytes()); Issue issue = Issue.finder.byId(1L); Long userId = 1L; // When new Attachment().store(foo, "foo.txt", User.find.byId(userId).asResource()); new Attachment().store(bar, "bar.html", User.find.byId(userId).asResource()); Attachment.moveAll(User.find.byId(userId).asResource(), issue.asResource()); List<Attachment> attachedFiles = Attachment.findByContainer(issue.asResource()); // Then assertThat(attachedFiles.size()).isEqualTo(2); assertThat(attachedFiles.get(0).name).isEqualTo("foo.txt"); assertThat(attachedFiles.get(0).mimeType).isEqualTo("text/plain"); assertThat(attachedFiles.get(1).name).isEqualTo("bar.html"); assertThat(attachedFiles.get(1).mimeType).isEqualTo("text/html"); } public File createFileWithContents(String name, byte[] contents) throws IOException { File tempFile = java.io.File.createTempFile(name, null); tempFile.deleteOnExit(); FileOutputStream os = new FileOutputStream(tempFile); os.write(contents); os.close(); return tempFile; } }

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
login with Google Sign in with Google
Reset password | Sign up