/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.way.gdrive;
import static br.com.objectos.way.base.testing.WayMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.File;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.io.CharSink;
import com.google.common.io.CharSource;
import com.google.common.io.Files;
/**
* @author mario.marques@objectos.com.br (Mario Marques Junior)
*/
@Test
public class GDirectoryTest {
private GDrive drive;
@BeforeClass
public void setUp() {
GDriveTokens tokens = GDrive.tokens()
.accessToken("ya29.1.AADtN_WYyuyZRG82oo2GxeKBVArXEHqsDnCj6PfYwxxNIuSMNydUh2cV6crz8Fc")
.refreshToken("1/1cCX3MGANg_fXQRHP07UKRSpowE3eAGT5sNOm67F8nQ")
.build();
drive = GDrive.authorize(tokens);
}
public void mkdir_must_work() {
GDirectory directory = drive.root();
GDirectory res = directory.mkdir("temp0");
assertThat(res.getName(), equalTo("temp0"));
}
public void mkdir_inner_dir_must_work() {
String directoryId = "0B1fV80wEwsDzalN6Z3VWNVNFSkU"; // folder
GDirectory directory = drive.directory(directoryId);
GDirectory res = directory.mkdir("temp1");
assertThat(res.getName(), equalTo("temp1"));
}
public void write_file_must_work() throws Exception {
String directoryId = "0B1fV80wEwsDzalN6Z3VWNVNFSkU"; // folder
GDirectory directory = drive.directory(directoryId);
File file = new File("write");
CharSink charSink = Files.asCharSink(file, Charsets.UTF_8);
CharSource
.wrap("write")
.copyTo(charSink);
GFile res = directory.write(file);
assertThat(res.getName(), equalTo("write"));
file.delete();
}
}