-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use reflection to extract JSON field names from Post class when popul…
…ating map for post creation.
- Loading branch information
1 parent
ffb0489
commit 01d2329
Showing
2 changed files
with
80 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 31 additions & 2 deletions
33
src/test/java/com/afrozaar/wordpress/wpapi/v2/WordpressClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
package com.afrozaar.wordpress.wpapi.v2; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.afrozaar.wordpress.wpapi.v2.config.ClientConfig; | ||
import com.afrozaar.wordpress.wpapi.v2.config.ClientFactory; | ||
import com.afrozaar.wordpress.wpapi.v2.model.Post; | ||
import com.afrozaar.wordpress.wpapi.v2.model.builder.PostBuilder; | ||
import com.afrozaar.wordpress.wpapi.v2.model.builder.TitleBuilder; | ||
|
||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author johan | ||
*/ | ||
public class WordpressClientTest { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(WordpressClientTest.class); | ||
Wordpress wordpress = ClientFactory.fromConfig(ClientConfig.of("http://localhost", "username", "password", false, true)); | ||
|
||
@Test | ||
public void TestCreateClient() { | ||
Wordpress wordpress = ClientFactory.fromConfig(ClientConfig.of("http://localhost", "username", "password", false, true)); | ||
|
||
System.out.println("media = " + wordpress.getMedia(10L)); | ||
} | ||
|
||
@Test | ||
public void PostFieldProcessingTest() { | ||
|
||
Post post = PostBuilder.aPost() | ||
.withTitle(TitleBuilder.aTitle().withRendered("foobar").build()) | ||
.withModifiedGmt(Instant.now().toString()) | ||
.withContent(null) | ||
.withFormat("myformat") | ||
.build(); | ||
|
||
final Map<String, Object> fieldMap = ((Client) wordpress).fieldsFrom(post); | ||
|
||
assertThat(fieldMap).containsOnlyKeys("title", "modified_gmt","format"); | ||
|
||
LOG.debug("map to post: {}", fieldMap); | ||
|
||
} | ||
|
||
} |