Created
August 7, 2023 02:37
-
-
Save A-pZ/986167c896d2cd8409fa36c3ea4239ab to your computer and use it in GitHub Desktop.
取引先の更新処理
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
public void update(String objectId, Company company, AuthenticationResult authenticationResult) { | |
salesforceWebClient.patch() // 更新はPATCH | |
.uri( salesforceProperties.getApplicationPath()+ "/sobjects/Account/" + objectId) // 更新対処の取引先のオブジェクトIDを指定 | |
.header("Authorization", authenticationResult.bearerToken()) // 認証結果 | |
.contentType(MediaType.APPLICATION_JSON) | |
.body(Mono.just(company), Company.class).retrieve() | |
.toBodilessEntity() | |
.block(); | |
} |
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
package com.github.apz.salesforcesample.repository | |
import com.github.apz.salesforcesample.model.Company | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.boot.test.context.SpringBootTest | |
import spock.lang.Specification | |
@SpringBootTest | |
class SalesforceUpdateTest extends Specification { | |
@Autowired | |
SalesforceAuthentication authentication | |
@Autowired | |
CompanyRepository repository | |
def "更新"() { | |
when: | |
def company = new Company() | |
company.setName("更新テストを行った会社") | |
def authenticationResult = authentication.authentication() | |
repository.update("0010l00001dKU2XAAW", company, authenticationResult) // 第1引数のidは、登録した取引先のidを指定 | |
then: | |
noExceptionThrown() | |
} | |
def "更新失敗"() { | |
when: | |
def company = new Company() | |
company.setName("更新テストを失敗する会社") | |
def authenticationResult = authentication.authentication() | |
repository.update("faildata", company, authenticationResult) | |
then: | |
WebClientResponseException ex = thrown() | |
ex.statusCode == HttpStatus.NOT_FOUND | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment