/*
 * Copyright 2011 the original author or authors.
 *
 * 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 org.springframework.social.vkontakte.api.impl;

import org.junit.Test;
import org.springframework.social.MissingAuthorizationException;
import org.springframework.social.vkontakte.api.Post;
import org.springframework.social.vkontakte.api.VKontakteErrorException;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;

/**
 * {@link WallTemplate} test.
 * @author vkolodrevskiy
 */
public class WallTemplateTest extends AbstractVKontakteApiTest {
    @Test
    public void post() {
        mockServer.expect(requestTo("https://api.vk.com/method/wall.post?access_token=ACCESS_TOKEN&v=3.0&message=hello"))
                .andExpect(method(GET))
                .andRespond(withSuccess(jsonResource("wall-post-response-3_0"), APPLICATION_JSON));
        String postId = vkontakte.wallOperations().post("hello");
        assertEquals("511", postId);
    }

    @Test(expected = VKontakteErrorException.class)
    public void post_expiredToken() {
		mockServer.expect(requestTo("https://api.vk.com/method/wall.post?access_token=ACCESS_TOKEN&v=3.0&message=hello"))
			.andExpect(method(GET))
			.andRespond(withSuccess(jsonResource("error-code-5"), APPLICATION_JSON));

		vkontakte.wallOperations().post("hello");
    }

    @Test(expected = MissingAuthorizationException.class)
    public void post_unauthorized() {
        unauthorizedVKontakte.wallOperations().post("hello");
    }

    // TODO: add more tests for posts
    @Test
    public void getPosts() {
        mockServer.expect(requestTo("https://api.vk.com/method/wall.get?access_token=ACCESS_TOKEN&v=3.0"))
                .andExpect(method(GET))
                .andRespond(withSuccess(jsonResource("wall-getposts-response-3_0"), APPLICATION_JSON));
        List<Post> posts = vkontakte.wallOperations().getPosts();
        assertEquals(20, posts.size());
        assertEquals("1627", posts.get(0).getId());
        assertEquals(3, posts.get(0).getAttachments().size());
    }
}

@@ -726,166 +726,27 @@
 ial.
-MissingAuthorizationException;%0Aimport org.springframework.social.vkontakte.api.Post;%0Aimport org.springframework.social.vkontakte.api.VKontakteErrorException;%0A
+vkontakte.api.Post;
 %0Aimp
@@ -765,17 +765,16 @@
 l.List;%0A
-%0A
 import s
@@ -1272,16 +1272,16 @@
 kiy%0A */%0A
+
 public c
@@ -1341,942 +1341,8 @@
 t %7B%0A
-    @Test%0A    public void post() %7B%0A        mockServer.expect(requestTo(%22https://api.vk.com/method/wall.post?access_token=ACCESS_TOKEN&v=3.0&message=hello%22))%0A                .andExpect(method(GET))%0A                .andRespond(withSuccess(jsonResource(%22wall-post-response-3_0%22), APPLICATION_JSON));%0A        String postId = vkontakte.wallOperations().post(%22hello%22);%0A        assertEquals(%22511%22, postId);%0A    %7D%0A%0A    @Test(expected = VKontakteErrorException.class)%0A    public void post_expiredToken() %7B%0A%09%09mockServer.expect(requestTo(%22https://api.vk.com/method/wall.post?access_token=ACCESS_TOKEN&v=3.0&message=hello%22))%0A%09%09%09.andExpect(method(GET))%0A%09%09%09.andRespond(withSuccess(jsonResource(%22error-code-5%22), APPLICATION_JSON));%0A%0A%09%09vkontakte.wallOperations().post(%22hello%22);%0A    %7D%0A%0A    @Test(expected = MissingAuthorizationException.class)%0A    public void post_unauthorized() %7B%0A        unauthorizedVKontakte.wallOperations().post(%22hello%22);%0A    %7D%0A%0A
     

fix unit tests